Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker exec not able to update the /etc/hosts file in a running container #15615

Closed
anshumanbh opened this issue Aug 15, 2015 · 3 comments
Closed

Comments

@anshumanbh
Copy link

docker version is 1.7.0, build 0baf609

I am trying to edit the /etc/hosts file of a running container by using the command:
docker exec <container-id> echo <ip> <server> >> /etc/hosts

And, I get the permission denied error message:
bash: /etc/hosts: Permission denied

However, when I run the following command:
docker exec -it <container-id> /bin/sh

and then manually edit the /etc/hosts file after attaching into that container, it works fine.

Any idea what I am missing here?

@anshumanbh
Copy link
Author

docker info
Containers: 2
Images: 105
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 118
Dirperm1 Supported: true
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.18.0-kali3-amd64
Operating System: Kali GNU/Linux 1.1.0 (moto)
CPUs: 4
Total Memory: 9.79 GiB
Name: kali
ID: URLU:WG5F:RJAB:4WHX:JFPW:N3UR:G644:K7EI:QPER:J66Z:3XGY:FW6Q
WARNING: No memory limit support
WARNING: No swap limit support

uname -a
Linux kali 3.18.0-kali3-amd64 #1 SMP Debian 3.18.6-1~kali2 (2015-03-02) x86_64 GNU/Linux

docker version
Client version: 1.7.0
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 0baf609
OS/Arch (client): linux/amd64
Server version: 1.7.0
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 0baf609
OS/Arch (server): linux/amd64

@anshumanbh
Copy link
Author

Apologies, I found the answer
docker exec <> /bin/sh -c "echo <> <> >> /etc/hosts"

@thaJeztah
Copy link
Member

Yup. Also see #15604 (comment) for those looking for an explanation 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants