Menu

Dipesh Majumdar

Blog and Paintings

Environment Variable in Docker

[dipesh.majumdar@demo ubunutu]$ cat Dockerfile
FROM ubuntu
#CMD sleep 5
#CMD ["sleep","30"]
ENV env_var1 "100"
ENTRYPOINT ["sleep"]
CMD ["35"]

[dipesh.majumdar@demo ubunutu]$ docker build -t ubuntu_cust:v1 .
Sending build context to Docker daemon 3.072 kB
Step 1/4 : FROM ubuntu
 ---> 94e814e2efa8
Step 2/4 : ENV env_var1 "100"
 ---> Running in e1643d4f4265
 ---> 086a4fc18f7b
Removing intermediate container e1643d4f4265
Step 3/4 : ENTRYPOINT sleep
 ---> Running in 7ff22b4c5347
 ---> f4fc9bd48ea5
Removing intermediate container 7ff22b4c5347
Step 4/4 : CMD 35
 ---> Running in 2cf6577075e8
 ---> 6cac7df40451
Removing intermediate container 2cf6577075e8
Successfully built 6cac7df40451

[dipesh.majumdar@demo ubunutu]$ docker run -dit -e ENV_VAR2=200 --name my_container ubuntu_cust:v1 5000
8c57561061ea615ab15695f7ab99ca263a337cc52e4eaf2c20f16a38039b8373
[dipesh.majumdar@demo ubunutu]$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
8c57561061ea        ubuntu_cust:v1      "sleep 5000"        8 seconds ago       Up 7 seconds                            my_container

 

[dipesh.majumdar@demo ubunutu]$ docker exec -it my_container env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=8c57561061ea
TERM=xterm
ENV_VAR2=200
env_var1=100
HOME=/root

 

Go Back

Comment