Writing a Dockerfile
Updated on October 27, 2026
Writing a Dockerfile
A few principles that keep your images lightweight and your builds fast on Webgune.
Multi-stage: Node.js example
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
CMD ["node", "dist/server.js"]
The builder stage contains the compilation tools and the npm cache; only the strict minimum needed is copied into the final stage, which drastically reduces the size of the delivered image.
Multi-stage: Go example
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY go.* ./
RUN go mod download
COPY . .
RUN go build -o server .
FROM alpine:latest
COPY --from=builder /app/server /server
CMD ["/server"]
Checklist before pushing
- The application listens on
0.0.0.0:$PORT, not on a hardcoded port. - No secret is copied into the image: everything goes through environment variables.
- A
.dockerignoreexcludesnode_modules,.git,.env. - The final image uses a lightweight base (
alpine,slim) whenever possible.