I have this command:
docker run -e "DB_HOST=thehost" --rm my_application echo $DB_HOST
but it shows nothing. I was expecting "thehost" to be shown.
I have tried with simple quotes, double quotes and without quotes.
What am I missing? Do I need to specify ENV parameter in my_aplication's Dockerfile?
If I do:
docker run -e "DB_HOST=thehost" --rm my_application echo $PATH
It shows the PATH value properly. But it is ignoring my env var.
There are a couple of layers of things here:
In your first example
your local shell catches the variable reference before it ever gets passed on to Docker.
If you explicitly single-quote it
Docker will find
/bin/echo
(assuming it exists in the container) and launch that with the string$DB_HOST
as an argument, but again, since no shell is involved on the Docker side, it dutifully prints out that string as is.The immediate answer to your question is to force there to be a shell on the Docker side
At a slightly higher level:
os.environ
, Ruby'sENV
, Node'sprocess.env
, etc.)#!/bin/sh
)CMD some command
, Docker will automatically wrap that in a shell; that is equivalent toCMD ["sh", "-c", "some command"]
ENTRYPOINT
, but it is probably a bug to use it that way