Docker Documentation References:
The purpose of this kata is to familiarize yourself with the process of overriding an environment variable that was set in the Dockerfile.
In this exercise we will create a simple Dockerfile and set an environment variable with will impact the output of the application. We will then delete the image.
Use and editor to create a file named sh_hello_user_Dockerfile, or copy the sh_hello_user_Dockerfile from this repository.
The file should contain the following
FROM alpine:3.6
MAINTAINER [email protected]
ENV DOCKER_USER_NAME Timmy
ENTRYPOINT [ "sh", "-c", "echo $DOCKER_USER_NAME" ]
Command
docker build -f sh_hello_user_Dockerfile .
Output
thought:DockerKata rich$ docker build -f sh_hello_user_Dockerfile .
Sending build context to Docker daemon 434.2 kB
Step 1/4 : FROM alpine:3.6
---> a41a7446062d
Step 2/4 : MAINTAINER [email protected]
---> Running in a78b6083f640
---> dc97dfd78be5
Removing intermediate container a78b6083f640
Step 3/4 : ENV DOCKER_USER_NAME Timmy
---> Running in e52461bfa94a
---> 56d9cb50cc30
Removing intermediate container e52461bfa94a
Step 4/4 : ENTRYPOINT sh -c echo $DOCKER_USER_NAME
---> Running in 72f900e1536b
---> 804eb58d237f
Removing intermediate container 72f900e1536b
Successfully built 804eb58d237f
Command
docker images
Output
thought:DockerKata rich$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 804eb58d237f 3 seconds ago 3.97 MB
Note: We will use the
IMAGE ID
which will differ from machine to machine, so you must select what is on your computer for the next two steps.
Command
docker run --env DOCKER_USER_NAME=$USER 804eb58d237f
Output
thought:DockerKata rich$ docker run --env DOCKER_USER_NAME=$USER 804eb58d237f
rich
Command
docker rmi -f 804eb58d237f
Output
thought:DockerKata rich$ docker rmi -f 804eb58d237f
Deleted: sha256:804eb58d237fb2b1dbe66d548779419825aaff1bd7b1d42c0216ec596569e846
Deleted: sha256:56d9cb50cc306cd2ce5a130bb99948a51d8261572a336b605a1304b74269ce1e
Deleted: sha256:dc97dfd78be5133d39a36e9962fbe197e92744c373684a1cbf295ff3afdaec69