Back to questionsWhy does this Dockerfile switch to
JuniorTheoryCommon
Why does this Dockerfile switch to USER 1000:1000 before CMD?
FROM node:22-slim
WORKDIR /app
COPY --chown=1000:1000 . .
USER 1000:1000
CMD ["node", "server.js"]Without USER, the app runs as root, UID 0, the same user as root on the host. A hole in the app or a mounted host folder then gives an attacker root's rights; USER 1000:1000 runs the process as an ordinary user.
- Believing root inside a container is harmless because the container is isolated
- Putting
USER 1000:1000beforeRUNsteps that need root, such asapt-get install, then breaking the build
- Why does the
COPYline use--chown=1000:1000? - How does Kubernetes refuse to start a container that would run as root?