Skip to content

Instantly share code, notes, and snippets.

@EricLondon
Created October 17, 2017 15:32
Show Gist options
  • Save EricLondon/b7ea60c04ee968410580428079a7c2f9 to your computer and use it in GitHub Desktop.
Save EricLondon/b7ea60c04ee968410580428079a7c2f9 to your computer and use it in GitHub Desktop.
Docker build arguments
FROM busybox
ARG MESSAGE
RUN echo $MESSAGE > message.txt
#!/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
./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