moby: Unable to modify /etc/hosts file in a container
As part of my test setup, the setup script needs to append a line to /etc/hosts
Doing sudo echo "127.0.0.1 foo.bar" >> /etc/hosts
results in the following error when executed inside a container
/bin/sh: /etc/hosts: Read-only file system
Googled the error and based on a suggestion from superuser.com issued the command sudo -- sh -c "echo test >> /etc/hosts"
. But it results in the same error
vi /etc/hosts
opens the file in read-only mode. Changing permission doesn’t work as well.
bash-3.2# chmod a+w /etc/hosts
chmod: changing permissions of `/etc/hosts': Read-only file system
Any suggestions?
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Reactions: 9
- Comments: 20 (7 by maintainers)
Commits related to this issue
- hubot: Add a hubot image I had to instal Git to avoid a: GET https://registry.npmjs.org/scoped-http-client GET https://registry.npmjs.org/async ERR! not found: git npm ERR! ERR! Failed u... — committed to wking/dockerfile by wking 10 years ago
- hubot: Add a hubot image I had to instal Git to avoid a: GET https://registry.npmjs.org/scoped-http-client GET https://registry.npmjs.org/async ERR! not found: git npm ERR! ERR! Failed u... — committed to wking/dockerfile by wking 10 years ago
- This is a copy of a private repository that is being worked on. Current status: * creates vagrant/docker host from oracle65 image * creates a puppetmaster with embedded puppetdb * has the abili... — committed to denmat/vagrant-docker by deleted user 10 years ago
- Adding support for Docker containers by adding run_as_user * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=514214 * https://github.com/dotcloud/docker/issues/1951 dnsmasq tries to drop privi... — committed to denmat/puppet-dnsmasq by deleted user 10 years ago
- Adding support for Docker containers by adding run_as_user * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=514214 * https://github.com/dotcloud/docker/issues/1951 dnsmasq tries to drop privi... — committed to denmat/puppet-dnsmasq by deleted user 10 years ago
- Merge pull request #1951 from msabansal/savefail Ignore failure to save hns endpoint to store — committed to cpuguy83/docker by mavenugo 7 years ago
You can do that using in your docker-compose.yml using
extra_hosts
. For instance:–add-host “example.com:127.0.0.1”
$ sudo docker run -i -t --add-host "example.com:127.0.0.1" testing/centos /bin/bash
If one wants to modify the default hosts file (not just add a new entry with --add-host docker run flag), it can be done dynamically when for example CMD is executed:
0.8.1 breaks the dnsmasq workaround because of this commit: https://github.com/alexlarsson/docker/commit/02fddffd51da782f912e2709ea814c330269515b
You will get:
To fix add
user=root
to/etc/dnsmasq.conf
See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=514214Thanks this worked
I had the same issue and solved it using
vi
inex
mode.ex -sc '%s/foo/bar/g|x' /etc/hosts
Hi @creack
I tried to umount and mount /etc/hosts but I’m still getting a Read-only file system error:
If I just unmount:
A mount variation:
Any idea how to modify /etc/hosts?