Home > OS >  Docker build hangs when adding user with a large value of user ID / UID
Docker build hangs when adding user with a large value of user ID / UID

Time:08-14

When trying to build a docker image with a large value of UID, such as 1000123456 (e.g. when trying to hard-code - for tests and debug only - a UID within the range of values accepted by one of Openshift/OKD namespaces), docker build repeatedly hangs on the line with RUN useradd.

To 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 solutions (to accept) or at least workarounds (to upvote)?

As a side-effect of this issue, the build takes up huge amount of disk space (any proposed workarounds should be free of this side-effect):

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

Total reclaimed space: 648.1GB

CodePudding user response:

You can use the useradd's --no-log-init option (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. Using --no-log-init avoids creating these files (huge in the case you add a user with a large uid). I don't know why these files are huge, but I think it is something related to Ubuntu users management?

References (it seems to be a known issue for a long time):

CodePudding user response:

Please, introduce the following instructions:

RUN apt -y update
RUN apt -y install strace
RUN strace useradd -m -s /bin/bash -N -u 123456 jovyan

You can see that useradd exits and docker build terminates as expected.

Now, change UID into 1000123456: useradd terminates as the previous scenario, but docker doesn't.

I suppose may be a bug in the Ubuntu image.

I suggest you to try with another image...

Let me know if it will work.

Regards.

  • Related