Docker Community Forums

Share and learn in the Docker community.

Docker image sizes for different user ids?

docker

(Drewmorgan) #1

I’ve noticed that, for a base image of ubuntu at least, when I do a “RUN useradd” in my Dockerfile, that the resulting image size changes as a function of the UID specified for the user… Its not a little change either, and as the UID gets rather large, the resulting image is huge… Here’s my Docker file:

FROM ubuntu

RUN useradd -ms /usr/bin/tcsh -u 1000 -g users id1000
#RUN useradd -ms /usr/bin/tcsh -u 10000 -g users id10000
#RUN useradd -ms /usr/bin/tcsh -u 100000 -g users id100000
#RUN useradd -ms /usr/bin/tcsh -u 1000000 -g users id1000000
#RUN useradd -ms /usr/bin/tcsh -u 10000000 -g users id10000000

CMD ["/usr/bin/tcsh"]

If I build an image from the file as shown, the resulting size is 111MB…

If I comment the “RUN useradd” line with UID 1000, and uncomment the one with UID 10000000, and build an image from it, the resulting size is 3.35GB :exclamation:

In fact, here’s the “docker images” for each:

docker-check-id10000000 latest b74918a8447b 19 seconds ago 3.35GB
docker-check-id1000000 latest bc20674c3cf5 59 seconds ago 435MB
docker-check-id100000 latest 890b82984181 About a minute ago 143MB
docker-check-id10000 latest 872f5e42142e About a minute ago 114MB
docker-check-id1000 latest 72016a7278ba About a minute ago 111MB

Why does a different UID of an added user affect the image size so much, and is there a way around it other than just using small UIDs?


(David Maze) #2

You could start the container and check yourself. This sounds like some artifact of the way useradd works on Ubuntu and isn’t anything Docker-specific.

…a Docker container tends to run a single process as a single user…why do you need a uid that high at all?


(Drewmorgan) #3

I should have thought to run interactively and use du to investigate… FWIW, the difference is in /var/log/lastlog and /var/log/faillog… The file “lastlog” is 288K for the one with UID 1000, but 2.8G for the one with UID 10000000…

Anyhow, thanks for pointing me in that direction… Now on to figuring out why that happens…