Docker
Beginner
1 min read
ARG, ENV, and HEALTHCHECK
Example
# ARG before FROM affects the FROM line only
ARG NODE_VERSION=20
FROM node:${NODE_VERSION}-alpine
# ARG after FROM is scoped to this build stage
ARG APP_VERSION=dev
ARG BUILD_DATE
WORKDIR /app
# ENV persists in the running container
ENV NODE_ENV=production \
PORT=3000 \
APP_VERSION=${APP_VERSION}
# OCI standard labels
LABEL org.opencontainers.image.version="${APP_VERSION}" \
org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.source="https://github.com/myorg/myapp"
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
COPY src/ ./src/
EXPOSE 3000
# HEALTHCHECK: test every 30s, timeout 5s, 3 retries
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget -qO- http://localhost:3000/health || exit 1
CMD ["node", "src/server.js"]
# Build:
# docker build \
# --build-arg APP_VERSION=2.1.0 \
# --build-arg BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
# -t myapp:2.1.0 .
Related Resources
Docker Reference
Complete tag & property list
Docker How-To Guides
Step-by-step practical guides
Docker Exercises
Practice what you've learned
More in Docker