docker build . when it prints the environment variable?FROM alpine ARG APP_VERSION=1.0 ENV APP_VERSION=$APP_VERSION RUN echo "App version is $APP_VERSION"
The ARG APP_VERSION is set to 1.0 during build. The ENV instruction sets APP_VERSION to the ARG value, so the RUN command prints the value 1.0.
ARG variables exist only during the image build process. ENV variables persist in the image and are available when the container runs.
ARG PORT=8080 ENV PORT=80 CMD echo $PORTWhat will be the output when running the container, and why?
ENV PORT=80 sets the environment variable PORT inside the image. ARG PORT=8080 is only available during build and does not affect runtime environment variables.
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?ARG VERSION=1.0 sets a build-time variable. ENV APP_MODE=production sets a default runtime variable. The run command overrides APP_MODE with development.
ARG variables are not persisted in the final image layers, so sensitive data passed as ARG is not stored in the image. ENV variables are stored in image layers and can be seen by anyone with the image.