How do I Docker COPY as non root?
While building a Docker image, how do I
COPY a file into the image so that the resulting file is owned by a user other than root?
One Solution collect form web for “How do I Docker COPY as non root?”
Docker currently doesn’t support
COPY as a user other than root. You need to
chmod the file after the
from centos:6 RUN groupadd -r slcs && adduser -r -g myuser myuser USER myuser #Install code, configure application, etc... USER root COPY run-my-app.sh /usr/local/bin/run-my-app.sh RUN chown myuser:myuser /usr/local/bin/run-my-app.sh && \ chmod 744 /usr/local/bin/run-my-app.sh USER myuser ENTRYPOINT ["/usr/local/bin/run-my-app.sh"]
I’ve been trying to follow the discussion through multiple GitHub issues: 6119, 9943, 13600, 27303, 28499
At the time of this post, Issue 30110 seems to be the most current which has no resolution. Therefore, it seems it is still not possible to do this with regular docker commands.
Also, the Dockerfile Reference for the
COPY command still says that
All new files and directories are created with a UID and GID of 0.