Permission denied in Docker container upon COPY and RUN of a file from git
TL;DR: Using COPY
to copy files into a Docker container retains the permissions from the host system. If host obtains the files from git
, make sure that file attributes are set correctly in git
to avoid getting a “Permission denied” error when using RUN
to execute these files in the Docker container.
Situation: Have a Dockerfile
which copies scripts/install_packages.sh
inside and executes it:
Problem: The execution always fails with “Permission denied” when the Docker container runs in GitLab, even though execute permissions are granted on install_packages.sh
on the local file system.
Solution: Use git update-index --chmod+x <filename>
to grant the execute permissions within git
, so that when GitLab clones the file it has the execute permission.