Have variables in the .env file with '*'
and '!'
chars in them. Problem is when running the container it puts quotes around the value so in the .env file : VAR1=docker321*!
becomes 'docker321*!
in the container environment. Tried escaping like docker321\*\!
and still the same thing happens. Any way around this?
I’ve tried to fix your post by adding Markdown backticks for `code`
, to ensure whatever you typed is not interpreted by the forum when being displayed. But please use the gray pencil icon/button to edit your post, as I doubt that the single quote is only added as a prefix in 'docker321*!
? Did you mean 'docker321*!'
?
In docker compose espacping is done with the $
character, not sure if it applies to the env-files as well though.
Tried it and the result is “docker321$*$!” so no, doesn’t work with env vars.
I’d say it’s not an issue with special characters. Even all of the following in an .env
file is quoted, at least when shown with set
:
a=123
b=abc456
c='123'
d='abc456'
e="123"
f="abc456"
docker run --rm -it --env-file .env busybox /bin/sh -c set
HOME='/root'
HOSTNAME='1d3be219cb86'
...
TERM='xterm'
a='123'
b='abc456'
c=''"'"'123'"'"
d=''"'"'abc456'"'"
e='"123"'
f='"abc456"'
However, no additional quoting with echo
:
docker run --rm --env-file .env busybox /bin/sh -c 'echo $b'
abc456
docker run --rm --env-file .env busybox /bin/sh -c 'echo $d'
'abc456'
docker run --rm --env-file .env busybox /bin/sh -c 'echo $f'
"abc456"
(And yes, same for a=docker321*!
and the like, also when using docker run --rm -it --env-file .env busybox
and running the set
and echo
commands on the prompt.)
So, what exactly are you doing?