0
0
Dockerdevops~20 mins

ARG and ENV instructions in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ARG and ENV Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of ARG and ENV in Dockerfile build
Given the Dockerfile below, what will be the output of the command docker build . when it prints the environment variable?
Docker
FROM alpine
ARG APP_VERSION=1.0
ENV APP_VERSION=$APP_VERSION
RUN echo "App version is $APP_VERSION"
AApp version is null
BApp version is
CApp version is $APP_VERSION
DApp version is 1.0
Attempts:
2 left
💡 Hint
Remember ARG is available only during build, ENV sets environment variables for runtime and build.
🧠 Conceptual
intermediate
1:30remaining
Difference between ARG and ENV in Dockerfile
Which statement correctly describes the difference between ARG and ENV instructions in a Dockerfile?
AARG is only available during build time; ENV is available during build and runtime.
BENV is only available during build time; ARG is available during build and runtime.
CBoth ARG and ENV are only available during runtime.
DARG and ENV are identical and interchangeable.
Attempts:
2 left
💡 Hint
Think about when you can access these variables: during image build or when running the container.
Troubleshoot
advanced
2:00remaining
Why does ENV not get the ARG value at runtime?
Consider this Dockerfile snippet:
ARG PORT=8080
ENV PORT=80
CMD echo $PORT
What will be the output when running the container, and why?
AEmpty output, because PORT is not set at runtime.
B8080, because ARG PORT is used at runtime.
C80, because ENV PORT overrides ARG PORT and is used at runtime.
DSyntax error during build.
Attempts:
2 left
💡 Hint
ENV sets the environment variable inside the image, ARG does not persist after build.
🔀 Workflow
advanced
2:30remaining
Passing build-time ARG and runtime ENV variables
You want to build a Docker image with a build-time variable VERSION defaulting to 1.0, and also allow overriding a runtime environment variable APP_MODE when running the container. Which Dockerfile and run command combination achieves this?
A
Dockerfile:
ENV VERSION=1.0
ARG APP_MODE=production
RUN echo $APP_MODE

Run: docker run -e VERSION=development image
B
Dockerfile:
ARG VERSION=1.0
ENV APP_MODE=production
RUN echo $VERSION

Run: docker run -e APP_MODE=development image
C
Dockerfile:
ARG VERSION=1.0
ENV APP_MODE=production
RUN echo $APP_MODE

Run: docker run image
D
Dockerfile:
ENV VERSION=1.0
ENV APP_MODE=production
RUN echo $VERSION

Run: docker run -e APP_MODE=development image
Attempts:
2 left
💡 Hint
Remember ARG is for build-time, ENV sets default runtime variables, and -e overrides runtime variables.
Best Practice
expert
3:00remaining
Secure handling of sensitive data with ARG and ENV
Which approach is best to avoid leaking sensitive data like passwords in Docker images using ARG and ENV?
AUse ARG for sensitive data and do not set it as ENV to avoid storing it in the image layers.
BUse ENV for sensitive data so it is available at runtime and build time.
CHardcode sensitive data in the Dockerfile for consistency.
DUse ENV and ARG together to store sensitive data in both build and runtime.
Attempts:
2 left
💡 Hint
Think about which variables persist in the final image layers and which do not.