Created
October 17, 2017 15:32
-
-
Save EricLondon/b7ea60c04ee968410580428079a7c2f9 to your computer and use it in GitHub Desktop.
Docker build arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM busybox | |
ARG MESSAGE | |
RUN echo $MESSAGE > message.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MESSAGE="Hello World" | |
DOCKER_TAG="message_arg" | |
TEMP_CONTAINER="message_temp" | |
FILE_NAME="message.txt" | |
docker build --build-arg MESSAGE="$MESSAGE" -t $DOCKER_TAG -f Dockerfile . | |
docker run --name $TEMP_CONTAINER $DOCKER_TAG /bin/true | |
docker cp $TEMP_CONTAINER:$FILE_NAME ./ | |
docker rm $TEMP_CONTAINER | |
cat $FILE_NAME |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./main.sh | |
Sending build context to Docker daemon 4.096kB | |
Step 1/3 : FROM busybox | |
---> 54511612f1c4 | |
Step 2/3 : ARG MESSAGE | |
---> Using cache | |
---> 71b87fd2d159 | |
Step 3/3 : RUN echo $MESSAGE > message.txt | |
---> Running in 7606574a5305 | |
---> 414ec45901e6 | |
Removing intermediate container 7606574a5305 | |
Successfully built 414ec45901e6 | |
Successfully tagged message_arg:latest | |
message_temp | |
Hello World |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment