0
0
Dockerdevops~5 mins

ARG and ENV instructions in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the ARG instruction in a Dockerfile?
ARG defines a variable that users can pass at build time to customize the image build process. It is only available during the build and not in the final container.
Click to reveal answer
beginner
How does the ENV instruction differ from ARG in Dockerfiles?
ENV sets environment variables that are available both during build and in the running container. These variables persist in the final image.
Click to reveal answer
intermediate
Can you use an ARG variable to set an ENV variable in a Dockerfile? How?
Yes. You can use ARG to get a build-time value and then assign it to an ENV variable like this: ARG VERSION=1.0 ENV APP_VERSION=$VERSION
Click to reveal answer
beginner
What happens if you try to access an ARG variable in the running container?
ARG variables are not available in the running container. They only exist during the image build process and are discarded afterward.
Click to reveal answer
intermediate
Why is it useful to use ARG for sensitive data during build?
ARG variables are not saved in the final image, so they help keep sensitive data like passwords or tokens from being exposed in the running container.
Click to reveal answer
Which Dockerfile instruction sets a variable only available during build time?
AARG
BENV
CRUN
DCMD
If you want an environment variable to be available inside the running container, which instruction should you use?
ALABEL
BARG
CFROM
DENV
How can you pass a value to an ARG variable when building a Docker image?
Adocker build --env VAR=value
Bdocker build --build-arg VAR=value
Cdocker run -e VAR=value
Ddocker run --build-arg VAR=value
What is the default value of an ARG variable if not passed during build?
AThe value set in the Dockerfile after ARG
BUndefined and causes error
CEmpty string
DThe value of ENV variable with the same name
Which statement is true about ENV variables in Docker?
AThey are only available during build time.
BThey are discarded after the image is built.
CThey persist in the image and are available at runtime.
DThey cannot be overridden at container start.
Explain the difference between ARG and ENV instructions in Dockerfiles.
Think about when and where each variable is available.
You got /4 concepts.
    Describe how you can use ARG and ENV together to pass a build-time value into the running container.
    Use ARG to get the value, then ENV to keep it.
    You got /3 concepts.