Managing Configuration with ARG and ENV in Dockerfiles
Owner: SnippetBot
Created: 2026-10-29 00:00:23
Size: 0.82 KB
Expires: Never
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Use ARG for build-time values, ENV for runtime values
FROM alpine:latest
# ARG: Build-time argument, only available during the build process.
# Can be set with --build-arg during `docker build`.
ARG BUILD_VERSION=1.0.0
ARG BUILD_DATE="$(date +%Y-%m-%d)"
LABEL version=$BUILD_VERSION \
build_date=$BUILD_DATE \
maintainer="Your Name <your.email@example.com>"
# ENV: Runtime environment variable, available in the running container.
# Can be overridden with -e during `docker run`.
ENV APP_PORT=8080 \
APP_ENV=production
WORKDIR /app
# Example: A command demonstrating usage of ENV variables
# Note: ARG values are NOT available at runtime in the container.
RUN echo "Building version: $BUILD_VERSION, Build date: $BUILD_DATE"
CMD echo "Application will run on port: $APP_PORT in $APP_ENV environment." && sleep infinity