I'm trying to add a host to /etc/hosts
in a Docker image. I have the following line in my Dockerfile:
RUN echo 10.162.34.15 my-host-name >> /etc/hosts
When I run docker build
, I get the following error:
#8 0.624 /bin/sh: 1: cannot create /etc/hosts: Read-only file system
I've found various old questions from prior versions of Docker where /etc/hosts
was read-only, but nothing relevant to why this would be happening in a later version. I'm using Docker Desktop for Mac 3.3.3, Docker engine 20.10.6.
I'm aware of docker run --add-host
and extra_hosts
in docker-compose
. I'm willing to use one of these instead, but I'd like to at least understand the source of this error.