Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment variables in docker when exec docker run

Tags:

linux

docker

I've got a problem with environment variables in docker. When I run command:

$ docker run ubuntu /bin/bash -c "echo $HOME"

I've got response:

/Users/bylek

But when I run:

$ docker run -it ubuntu /bin/bash

and then:

root@5e079c47affa:/# echo $HOME

I've got:

/root

Second response is correct. Why first command return $HOME value from my host?

like image 735
Paweł Kapała Avatar asked Mar 15 '23 03:03

Paweł Kapała


1 Answers

echo $HOME is being evaluated on your host because you haven't got the syntax of the switch to bash correct. It's Linux so you need single quotes.

Try replacing your double quotes with single quotes.

eg. This is what I get:

bash-3.2$  docker run ubuntu /bin/bash -c 'echo $HOME'
/root
like image 188
jacks Avatar answered Mar 24 '23 11:03

jacks