Preparing your workspace
Container security requires reducing privileges, using trusted images, managing secrets safely, and limiting resource consumption.
Containers should run with the minimum privileges required. Whenever practical, production processes should avoid unnecessary root access. Base images should be kept updated and unnecessary packages should be removed. Secrets should come from secure runtime configuration or secret-management systems rather than being baked into images. Resource controls can prevent one container from consuming excessive CPU or memory. Container isolation is useful, but it should not be treated as a complete security boundary by itself.
A production API can run as a non-root user, use a minimal runtime image, receive secrets through deployment configuration, and have sensible CPU and memory limits.
FROM node:22-alpine WORKDIR /app RUN addgroup -S appgroup && adduser -S appuser -G appgroup COPY --chown=appuser:appgroup . . USER appuser CMD ["node", "server.js"]
The application runs as a non-root user inside the container.