1

I am trying to add a line in /etc/hosts file with a specific IP and a hostname. The IP is static and the hostname is retrievable from the /etc/hostname.

However, I want my root file system to be read-only.

So I get the following error: /etc/hosts: Read-only file system

When I check with mount it is: ro.

So, I try to add /etc/hosts as an emptydir, but it is not allowed since /etc/hosts is already mounted with error: b'linux mounts: Duplicate mount point: /etc/hosts

I am also trying to remove /etc/hosts in the dockerfile and symblink it to another file but I get the following error: rm: cannot remove '/etc/hosts': Device or resource busy

If I don't mount as read_only the filesystem, the /etc/hosts is not rw, and I can normally make the change. Then, the /etc/hosts is not mounted as ro but rw. So this value is inherited.

I am using kubernetes manifest or docker compose to deploy the container image and I have concluded that I need something like the --add-host in docker, but retrieve the hostname dynamically from /etc/hostname.

    In `docker-compose`:
    extra_hosts:
      - "hostname:127.0.1.1"

    In `kubernetes-yaml`:
    hostAliases:
      - ip: "127.0.1.1"
        hostnames:
        - "hostname"

Is there a way to get the hostname as a variable in docker-compose and yaml?

Is there another way to bypass the ro mounted /etc/hosts file when the rootfile system is readonly?

belabrinel
  • 125
  • 1
  • 6

0 Answers0