When trying to build a docker image with a large value of UID, such as 1000123456
, 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)?
More info
This bug can manifest itself for example when trying to hard-code (for debug only) a UID within the range of values accepted by one of Openshift/OKD namespaces.
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
2
Answers
Please, introduce the following instructions:
You can see that
useradd
exits and docker build terminates as expected.Now, change
UID
into1000123456
: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.
You can use the
useradd
‘s--no-log-init
option (or shorter:-l
):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). Why are these files huge?Source: https://github.com/docker/hub-feedback/issues/2263#issuecomment-1205423533
References (it seems to be a known issue for a long time):