Docker-compose build error on mac : chmod: changing permissions of '/etc/resolv.conf': Read-only file system

Hi All,

After updating to the latest Docker version (Docker Desktop 4.26.1 (131620)), I encountered the following error on my Mac:

8/20] RUN rm -rf /root/.cache/pip     && chmod -R og+rwx /etc/:
0.492 chmod: changing permissions of '/etc/resolv.conf': Read-only file system
0.493 chmod: changing permissions of '/etc/hosts': Read-only file system
failed to solve: process "/bin/sh -c rm -rf /root/.cache/pip     && chmod -R og+rwx /etc/" did not complete successfully: exit code: 1

Below are the sequent of step in my docker file.

COPY requirements.txt /usr/local/bin/requirements.txt
RUN pip3 install -r /usr/local/bin/requirements.txt

RUN rm -rf /root/.cache/pip \
    && chmod -R og+rwx /etc/

I attempted to modify permissions for the Mac directory, but encountered restrictions preventing access permission changes in this directory.

Any assistance on resolving this issue would be greatly appreciated. Thank you in advance for your help.

What Mac directory? You are trying it in a Linux container, but you can’t because those files are not part of the container filesystem, but mounted and from the host and read-only during build. When you run a container from the built image, you will get another hosts file mounted to the container. Why do you want to change the permissions of the entire etc directory in a container?

I edited your post. please, format your posts next time according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

Example code block:

echo "I am a code."
echo "An athletic one, and I wanna run."