Building Custom Nginx Docker Images

1 min read

Authors
banner

Custom Nginx Docker Images

Advanced Dockerfile

FROM nginx:alpine
RUN apk add --no-cache openssl

COPY nginx.conf /etc/nginx/
COPY sites/ /etc/nginx/sites-enabled/
COPY ssl/ /etc/nginx/ssl/

RUN nginx -t

HEALTHCHECK --interval=10s --timeout=3s \
  CMD curl -f http://localhost/health || exit 1

EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]

Multi-Stage Build

FROM node:latest as builder
WORKDIR /app
COPY . .
RUN npm run build

FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Production images!

© 2025 Vijay Rajendran