What is the USER instruction good for in Docker?
Experience Level: Senior
Tags: Docker
Answer
The USER instruction sets the user name (or UID) and optionally the user group (or GID) to use when running the image and for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile.
Note that when specifying a group for the user, the user will have only the specified group membership. Any other configured group memberships will be ignored.
Example:
FROM ubuntu:latest
RUN apt-get -y update
RUN groupadd -r user && useradd -r -g user user
USER user
Related Docker job interview questions
Can the WORKDIR instruction resolve environment variables in Docker?
Docker SeniorWhat is the WORKDIR instruction good for in Docker?
Docker SeniorHow do you copy files to your Docker image during built while configuring permissions as well?
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 Senior