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}

Comments

No Comments Yet.
Be the first to tell us what you think.
Docker instructions
Docker instructions

Are you learning Docker ? Try our test we designed to help you progress faster.

Test yourself