Home > Blockchain >  Docker run env variable does not work with single quotes?
Docker run env variable does not work with single quotes?

Time:02-10

I was running the following command:

docker run -e 'SOME_ENV_VARIABLE=somevalue' somecommand

And this did not pass the env variable to somecommand (Note: SOME_ENV_VARIABLE and somevalue did not have un-escaped single quotes, they were capital snake case and lowercase respectively without special character.

Later, I tried:

docker run -e "SOME_ENV_VARIABLE=somevalue" somecommand

And this somehow worked (note the double quotes).

Why is this? I have seen documentation with single quotes.

I tried this on Windows.

CodePudding user response:

Quotation is handled by your shell - since you are on windows, that is cmd.exe. And, from what I understand, since cmd.exe does not handle single quotes, it will pass that argument with the quotes to docker.

It would work on Linux though (which usually has the bash shell), being the the environment many people would use docker on, and as such the reason it is present in a lot of documentation.

  • Related