What is the RUN instruction good for in Docker?
Experience Level: Senior
Tags: Docker
Answer
The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.
There are 2 forms:
Shell form:
RUN <command> (the command is run in a shell, which by default is /bin/sh -c on Linux or cmd /S /C on Windows)
Exec form:
RUN ["executable", "param1", "param2"]
The default shell for the shell form can be changed using the SHELL command.
Related Docker job interview questions
What is the ENTRYPOINT instruction good for in Docker?
Docker SeniorHow can you split a long RUN instruction on multiple lines in Dockerfile?
Docker SeniorAre ARG variables persisted into the built images in Docker?
Docker SeniorYou have a variable declared using ARG and the same variable declared using ENV instruction in your Dockerfile. What variable value will be used?
Docker SeniorWhat is the scope of a variable defined using the ARG instruction within a Dockerfile?
Docker Senior