SAK
SAK

Reputation: 25428

Setting environment in Dockerfile not reflecting in docker exec

Having trouble with setting environment in docker.

My Dockerfile has the following line:

ENV abc=hello

I build the docker image using:

 docker image build --no-cache -t foobar .

Run the container in daemon mode:

 docker run -it -d foobar   

Run docker container ls, find the container name and run:

docker exec -it suspicious_poincare echo $abc

It doesn't print "hello". Why is that?

Upvotes: 1

Views: 461

Answers (2)

The command you're trying to run is Chained command thus first command is being executed by container and second one is being executed by your host machine. Therefore, like @heydar-dasoomi suggested, you need to run in inside quotes the commands. Please read the discussion of Docker repo from following link https://github.com/docker/for-linux/issues/119.

Upvotes: 0

heydar dasoomi
heydar dasoomi

Reputation: 557

Use this:

docker exec -it suspicious_poincare bash -c "echo \$abc"

If don't do this,it will echo environment from your host.

Upvotes: 4

Related Questions