Intern
What is the difference between ENV and ARG in Dockerfile?
sobes.tech AI
Answer from AI
In a Dockerfile, ARG and ENV are used for different purposes:
-
ARGis a build argument. Its value can be passed during the image build process usingdocker build --build-arg. Arguments are only available at build time and are not stored in the final image. -
ENVis an environment variable that is stored in the image and available during container runtime.
Example:
ARG VERSION=1.0
ENV APP_VERSION=$VERSION
RUN echo "Building version $APP_VERSION"
Here, VERSION is set during build, and APP_VERSION will be available inside the container after it starts.