Does FROM instruction support variables within a Dockerfile?
Experience Level: Senior
Tags: Docker
Answer
Yes. You can use the ARG instruction. The ARG instruction defines a variable that users can pass at build-time to the builder with the docker build command using the --build-arg <varname>=<value> flag. If a user specifies a build argument that was not defined in the Dockerfile, the build outputs a warning.
ARG CODE_VERSION=latest
FROM base:${CODE_VERSION}
Related Docker job interview questions
How do you provide default values for variables defined using ARG instruction in Dockerfile?
Docker SeniorWhat is the ARG instruction good for in Docker?
Docker SeniorHow many times can the FROM instruction appear within a Dockerfile?
Docker SeniorWhat is the FROM instruction good for in Docker?
Docker SeniorAre Docker instructions case sensitive?
Docker Senior