User ID Policies
User ID Policies
ISO requirements prohibit running engines under the Administrator account. All submitted engines must meet this requirement. Engine images that are using the Administrator account will be rejected at ingestion. The official Dockerfile reference is at https://docs.docker.com/engine/reference/builder/#user
Windows Containers
Windows containers default to using the ContainerAdministrator account and so need to set a non-administrator user. The recommended account to use is ContainerUser which is available by default in Windows Server images. The command to set the user in a dockerfile is:
USER ContainerUserLinux Containers
Linux containers default to using the root user account and need to set a non-root account. Further, Linux containers are also required to set a numeric user id as opposed to a string. In Linux the root user maps to user id 0 and so the requirement is to set a non-zero user id. An appropriate least-permissions user is the nobody account which, in many distributions, maps to the user id 65534.
The mappings between user names and user ids is found in the etc/passwd file. As an example the following command will list user information from the python base image python:3.10-slim-bullseye.
docker run python:3.10-slim-bullseye cat etc/passwdThe output of this command lists all user information from the image.
root:x:0:0:root:/root:/bin/bashdaemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologinbin:x:2:2:bin:/bin:/usr/sbin/nologinsys:x:3:3:sys:/dev:/usr/sbin/nologinsync:x:4:65534:sync:/bin:/bin/syncgames:x:5:60:games:/usr/games:/usr/sbin/nologinman:x:6:12:man:/var/cache/man:/usr/sbin/nologinlp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologinmail:x:8:8:mail:/var/mail:/usr/sbin/nologinnews:x:9:9:news:/var/spool/news:/usr/sbin/nologinuucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologinproxy:x:13:13:proxy:/bin:/usr/sbin/nologinwww-data:x:33:33:www-data:/var/www:/usr/sbin/nologinbackup:x:34:34:backup:/var/backups:/usr/sbin/nologinlist:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologinirc:x:39:39:ircd:/run/ircd:/usr/sbin/nologingnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologinnobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin_apt:x:100:65534::/nonexistent:/usr/sbin/nologinA record in this file consists of seven colon seperated values. The first value is the user name and the third value is the corresponding user id. For this sample image the nobody user does indeed correspond to the user id 65534 as expected.
The command to set the user in a dockerfile is:
USER 65534