Docker Community Forums

Share and learn in the Docker community.

Useradd inside docker reuses existing uid

Hi,

After reading this link Understanding how uid and gid work in Docker containers | by Marc Campbell | Medium my understanding is that the kernel is the sole entity responsible for assigning uid numbers.

Therefore I would expect that running useradd inside a docker container would create a new uid for the newly created container user.
However what I see is that it will start returning uid starting from 1000 which is already existing.

To recreate:

  1. Check existing users and uid’s:
    cat /etc/passwd

  2. Run docker container interactively
    docker run -it archlinux:latest /bin/bash

  3. Run useradd
    useradd test_user

  4. Check test_user’s uid
    cat /etc/passwd | grep test_user

Can someone enlighten me on what is going on?
Edit: Maybe I should add that my host is archlinux as well.

Useradd inside docker reuses existing uid
Check existing users and uid’s: cat /etc/passwd.
Run docker container interactively. docker run -it archlinux:latest /bin/bash.
Run useradd. useradd test_user.
Check test_user’s uid. cat /etc/passwd | grep test_user.