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?
✗ Incorrect
ARG defines build-time variables, while ENV sets variables available at runtime.
If you want an environment variable to be available inside the running container, which instruction should you use?
✗ Incorrect
ENV sets environment variables that persist in the container at runtime.
How can you pass a value to an ARG variable when building a Docker image?
✗ Incorrect
Use --build-arg to pass values to ARG variables during docker build.
What is the default value of an ARG variable if not passed during build?
✗ Incorrect
ARG can have a default value in the Dockerfile, used if no build-arg is passed.
Which statement is true about ENV variables in Docker?
✗ Incorrect
ENV variables persist in the image and are accessible when the container runs.
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.