Users, Groups and Permissions
You start quicknotes in a container and run whoami inside it. The answer is root. That surprises most people, and it matters: if someone finds a hole in quicknotes, they get whatever power that user has. Understanding Linux users and permissions lets you fix it.
The rule
Containers run as root unless you say otherwise — so say otherwise.
Linux identifies every user by a number, the UID, and every group by a GID. Names like root or app are just labels looked up in /etc/passwd; the kernel only cares about the numbers. root is always UID 0 and may do almost anything.
Every file has an owner, a group, and three sets of permission bits. ls -l shows them:
$ ls -l /app
-rw-r--r-- 1 root root 812 app.py
-rwxr-x--- 1 app app 143 start.shAfter the first character (- for a file, d for a directory) come three triplets of read, write and execute: for the owner, the group, and others. As numbers, r = 4, w = 2, x = 1, added per triplet, so rwxr-x--- is 750. You change them with chmod and change the owner with chown.
In a Dockerfile you create an ordinary user and switch to it before the app starts:
RUN useradd --create-home app
USER app
CMD ["python", "app.py"]From USER app onward, later instructions and the running container use that user instead of root.