Moby: use docker exec to change /etc/hosts error

Created on 15 Aug 2015  路  1Comment  路  Source: moby/moby

hello, i use docker exec 1ebea17823f3 echo test >> /etc/hosts to change the container /etc/hosts, but i find that the container hosts do not change. it change the vm /etc/hosts.

Most helpful comment

I think this is expected, and not a bug in docker; basically what your doing is;

(docker exec 1ebea17823f3 echo test) >> /etc/hosts

(Added the parentheses to illustrate the problem) Basically, the echo test runs _inside_ the container, but the _output_ is returned to the host (vm) and added to /etc/hosts _of the VM_.

Try it this way, so that both the "echo" AND the >> /etc/hosts take place inside the container;

docker exec 1ebea17823f3 /bin/sh -c "echo test >> /etc/hosts"

I'm going to close this issue, because it's not a bug, but I hope the above explanation helps you further!

>All comments

I think this is expected, and not a bug in docker; basically what your doing is;

(docker exec 1ebea17823f3 echo test) >> /etc/hosts

(Added the parentheses to illustrate the problem) Basically, the echo test runs _inside_ the container, but the _output_ is returned to the host (vm) and added to /etc/hosts _of the VM_.

Try it this way, so that both the "echo" AND the >> /etc/hosts take place inside the container;

docker exec 1ebea17823f3 /bin/sh -c "echo test >> /etc/hosts"

I'm going to close this issue, because it's not a bug, but I hope the above explanation helps you further!

Was this page helpful?
0 / 5 - 0 ratings