1

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.

Vedant
  • 422
  • 1
  • 3
  • 21

1 Answers1

0

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.

Leonardo Dagnino
  • 2,914
  • 7
  • 28
  • Hmm, makes sense, but I'm wondering why it didn't work inside an alpine image either? – Vedant Feb 10 '22 at 04:49
  • 1
    I'd suggest you edit your question adding what exactly you tried to run and what error message you got - Alpine's shell definitely does handle single quotes, which can be tested by running `ls '/'`. It would be transparent to the application, which would not receive the quotes at all. – Leonardo Dagnino Feb 10 '22 at 04:53
  • Turns out it didn't work on Alpine, because of some other problem and spit out the exact same error, and worked on Alpine, by the time I had resolved that. Edited the question to Windows only for future readers – Vedant Feb 11 '22 at 06:23
  • @Vedant How did you fix it on alpine? Facing the same issue. – Nitish Parkar May 24 '23 at 07:26