Junior — Middle
How can parameters or arguments be passed to the Docker image build process via Dockerfile?
sobes.tech AI
Answer from AI
To pass parameters in Docker build process via Dockerfile, the ARG instruction is used. It allows defining variables whose values can be set during build with the --build-arg option.
Example Dockerfile:
FROM python:3.9
ARG APP_VERSION=1.0
RUN echo "Building version $APP_VERSION"
Building the image with an argument:
docker build --build-arg APP_VERSION=2.0 -t myapp:2.0 .
Thus, you can dynamically change build parameters without modifying the Dockerfile.