Assuming that I set an environment variable in my Dockerfile
like this:
FROM ubuntu:latest
ENV MY_NAME=YOYO
When running docker run -it my_image bash
I am able to access MY_NAME
like this:
root@dec16fb8dab1:/home $ echo $MY_NAME
YOYO
However, when I try docker run my_image echo $MY_NAME
, not surprisingly I get nothing (since there is no MY_NAME
variable on the host). How can I use docker run with a command to use the image's environement variables instead of the host's?
In a more general case, I need to see the output of docker run my_image cmd --flag $CONTAINER_ENV_VARIABLE
.