0

I want to modify permissions etc/hosts file in docker as I am continuously modifying it. I want to make particular user have the access or have the 744 access on it. I tried following in docker file.

USE root
RUN chown <user>:<group> /etc/hosts
USE root
RUN chmod 777 /etc/hosts

However this doesn't work and throws an exception on saying that etc/host is readable and hence can't change permission.

Amit Singh
  • 135
  • 1
  • 1
  • 8
  • 1
    I'd avoid changing `/etc/hosts` if at all possible. I'd _definitely_ avoid making a system-level file like this world-writeable; `chmod 0777` is almost always a security mistake. Since Docker manages the network environment of the container in general, you can't edit `/etc/hosts` in a Dockerfile. If you really absolutely can't set up a DNS server, the linked question describes a `docker run --add-host` option that's an alternative. – David Maze Jul 08 '22 at 13:19
  • i need it for experiment purpose. The idea is I am testing something but for that I need to keep editing etc/hosts file only issue is that the docker file is not able to modify it even if i try to run above commands as it says that the file is readonly. I am able to do docker exec and change the command though but i need a docker file solution. – Amit Singh Jul 08 '22 at 20:30
  • Any way just to test the approach? Everytime i try to change permission it says `changing permissions of '/etc/hosts': Read-only file system` even though i am root. but if i make the container up and run docker compose exec then the command runs. – Amit Singh Jul 09 '22 at 11:21

0 Answers0