How do you provide default values for variables defined using ARG instruction in Dockerfile?
Experience Level: Senior
Tags: Docker
Answer
An ARG instruction can optionally include a default value like this:
FROM busybox
ARG user1=someuser
ARG buildno=1
# ...
If an ARG instruction has a default value and if there is no value passed at build-time, the builder uses the default.
Related Docker job interview questions
You 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 SeniorWhat is the ARG instruction good for in Docker?
Docker SeniorDoes FROM instruction support variables within a Dockerfile?
Docker SeniorHow many times can the FROM instruction appear within a Dockerfile?
Docker Senior