How do you copy files to your Docker image during built while configuring permissions as well?
Experience Level: Senior
Tags: Docker
Answer
All new files and directories are created with a UID and GID of 0, unless the optional --chown flag specifies a given username, groupname, or UID/GID combination to request specific ownership of the copied content. The format of the --chown flag allows for either username and groupname strings or direct integer UID and GID in any combination. Providing a username without groupname or a UID without GID will use the same numeric UID as the GID. If a username or groupname is provided, the container’s root filesystem /etc/passwd and /etc/group files will be used to perform the translation from name to integer UID or GID respectively. The following examples show valid definitions for the --chown flag:
COPY --chown=55:mygroup files* /somedir/
COPY --chown=bin files* /somedir/
COPY --chown=1 files* /somedir/
COPY --chown=10:11 files* /somedir/
Related Docker job interview questions
What is the WORKDIR instruction good for in Docker?
Docker SeniorWhat is the USER instruction good for in Docker?
Docker SeniorWhat is the COPY instruction in Docker good for?
Docker SeniorHow can you view the values on the environment variables that were set using the ENV instruction in a Dockerfile?
Docker SeniorWill the variables set using the ENV instruction in a Dockerfile be persisted in the built image?
Docker Senior