Junior — Middle
How can a variable that changes during CI/CD execution be passed into the Docker image build process?
sobes.tech AI
Answer from AI
To pass a variable that changes during CI/CD execution into the Docker image build process, you can use build arguments.
For example, in the Dockerfile, declare an argument:
ARG VARIABLE_NAME
RUN echo "Variable is $VARIABLE_NAME"
When running the build in the CI/CD pipeline, pass the value:
docker build --build-arg VARIABLE_NAME=${VARIABLE_NAME} .
Where ${VARIABLE_NAME} is an environment variable or a parameter set in the CI/CD system.
This allows dynamically changing build parameters without modifying the Dockerfile. Arguments are only available during the build and do not become environment variables in the final image.