Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 580
Sara Avatar asked Dec 24 '15 00:12

Sara


People also ask

What does the Docker Copy command do?

COPY is a docker file command that copies files from a local source location to a destination in the Docker container.

Does Docker COPY make directory?

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).


2 Answers

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

like image 147
Armin Braun Avatar answered Sep 19 '22 01:09

Armin Braun


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.

like image 41
Jonathan Giroux Avatar answered Sep 20 '22 01:09

Jonathan Giroux