How to make docker COPY ignore file permissions?

Viewed 388

I'm pulling a docker image from registry and I want to use it as cache, running locally docker build --cache-from MY_IMAGE .. It uses case up to the layer COPY requirements.txt ${SOME_DIR}. I suspect the problem is that docker looks at the file permissions, not just the file content. Is there any way to make it ignore the file permissions?

Thanks in advance! :)

PS I could probably use RUN, HEREDOC and pipes to avoid using COPY, but it would look really awful.

Regards

1 Answers

After reading the question again, I guess the cache invalidation is the problem here - COPY command is invalidating cache when something changes, and permissions are part of the meta information, which are included for this calculation.

Permissions are noted, because hashing is used to detect changes. There is related question for this: Why does my Docker cache get invalidated by this COPY command?

There is no way around this - just use COPY command at the last point you could if your file permissions are different based on upstream registry image.

Permissions during the copy operation itself are not derived from the source, instead by default "All new files and directories are created with a UID and GID of 0", as based on the official docs.

However, you can change owner while using the COPY command.

You can use --chown parameter, with the user:group syntax, or by using UID:GID values.

Note, that this works only with Linux based containers. On Windows machines different concepts with permissions have been used, and usage of /etc/groups or /etc/passwd is not possible.

Related