linuxdockerfile-access

Docker COPY command give 777 access to the copied file


In my docker file I have below command:

USER gerrit
COPY gerrit-default-config /var/gerrit/etc/gerrit.config

Running the image I see that the file access number is 777. Is it default value? Is there a way to change the access other than running chmod after each COPY?

RUN chmod 600 /var/gerrit/etc/gerrit.config

Solution

  • The permissions are inherited from your host. If that file is on 777 on your host before copying then you get 777 in the container.

    If you don't want 777 here ever, just chmod it to 600 in the host.

    Source: https://github.com/docker/docker/issues/6333