What is the ENV instruction good for in Docker?
Experience Level: Senior
Tags: Docker
Answer
The ENV instruction sets the environment variable <key> to the value <value>. This value will be in the environment for all subsequent instructions in the build stage and can be replaced inline in many as well. The value will be interpreted for other environment variables, so quote characters will be removed if they are not escaped. Like command line parsing, quotes and backslashes can be used to include spaces within values.
Example:
ENV NAME="John Doe"
ENV DEPARTMENT="Research and Development"
ENV CITY="New York"
Related Docker job interview questions
How 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 SeniorWhat is the ENTRYPOINT instruction good for in Docker?
Docker SeniorHow can you split a long RUN instruction on multiple lines in Dockerfile?
Docker SeniorWhat is the RUN instruction good for in Docker?
Docker Senior