Running Containers as Root
DK · Common Mistakessyntax
# Problem:
FROM node:20
CMD ["node", "server.js"]
# Runs as root by defaultexample
# Fix:
FROM node:20-alpine
WORKDIR /app
COPY --chown=node:node . .
RUN npm ci --omit=dev
USER node
CMD ["node", "server.js"]Note Most base images default to root. This means if an attacker exploits your application, they have root inside the container — and potentially on the host via privilege escalation. Always add a USER instruction before CMD.