ARGis used to pass build-time variables- Available only during
docker build - Not available inside running container (unless passed to ENV)
ENVis used to define runtime environment variables- Available inside the container after it starts
Use ARG when you want to change base image version without modifying Dockerfile
ARG BASE_VERSION=22.04
FROM ubuntu:${BASE_VERSION}Build different versions:
docker build -t app:v1 --build-arg BASE_VERSION=20.04 .
docker build -t app:v2 --build-arg BASE_VERSION=22.04 .
ARG APP=nginx
RUN apt-get update && apt-get install -y ${APP}
Install different software using same Dockerfile
ENV APP_ENV=production
ENV DB_HOST=localhost
Configure app behavior (dev/test/prod
ENV DB_USER=admin
ENV DB_PASS=password
Provide runtime DB configuration
ARG APP_ENV=dev
ENV APP_ENV=${APP_ENV}
Pass value at build time โ use at runtime
docker build -t app --build-arg APP_ENV=production .
ARG MODE=prod
ENV MODE=${MODE}
Enable debug logs or optimizations