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
COPY is a docker file command that copies files from a local source location to a destination in the Docker container.
Docker Dockerfiles COPY InstructionThe COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest> . Multiple <src> resource may be specified but they must be relative to the source directory that is being built (the context of the build).
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
Update 2021: there's now a flag for ADD
and COPY
.
# syntax=docker/dockerfile:1.3
FROM debian:buster
COPY --chmod=0644 file /path
Because file usages are written in the Dockerfile (i.e. which serves as documentation), it makes sense to explicit the permissions in the Dockerfile too, rather than in another file hidden in the CICD process.
FTR Git does not store Unix permissions, only the executable flag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With