Linux – Docker builds hang when adding users with large user ID/UID values

Docker builds hang when adding users with large user ID/UID values… here is a solution to the problem.

Docker builds hang when adding users with large user ID/UID values

When trying to build a docker image with a large UID value, such as 1000123456, the docker build repeatedly gets stuck on the line of the RUN useradd

Reproduce:

$ touch Dockerfile
$ echo FROM ubuntu:latest >> Dockerfile
$ echo RUN useradd -m -s /bin/bash -N -u 1000123456 jovyan >> Dockerfile
$ docker build --tag mirekphd/test-uid .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM ubuntu:latest
 ---> d2e4e1f51132
Step 2/2 : RUN useradd -m -s /bin/bash -N -u 1000123456 jovyan
 ---> Running in 04707e01aefc

Any known solution (accepted) or at least workaround (in favor)?


More information

For example, this error manifests itself when attempting to hard-code a UID within the range of values accepted by one of the Openshift/OKD namespaces (for debugging only).

As a side effect of this

issue, builds consume a lot of disk space (any suggested workaround should avoid this side effect):

$ docker system prune -f
Deleted Containers: 
04707e01aefcda9ce9840389f1d59821e1ddb7dac535d416f99447e657ec5309
c3fc96209790ee7aa0c2c10bec2459e8ec3dbcc1dc7cfdd0a3e12960a28b9437
1ed4985b3e27eaff6394fd0243713573473ab59c9a82db865e40ebb40a391892

Total reclaimed space: 648.1GB

Solution

You can use the —no-log-init option of useradd (or shorter: -l):

useradd --no-log-init -m -s /bin/bash -N -u 1000123456 jovyan

The huge files created in the Docker image (/var/log/faillog and /var/log/laSTLog) are sparse files 。 Use –-no-log-init to avoid creating these files, which can be large if you add users with larger UIDs. Why are these files large?

useradd by default reserves space for all users, so when using (say), uid 10000, it reserves space for 10000 users, even if only user 10000 is used; for this, a sparse-file is created

Source: https://github.com/docker/hub-feedback/issues/2263#issuecomment-1205423533

Quotes (seems to be a long time ago known issue):

Related Problems and Solutions