I'm trying to create a new user with UID
1340816314
inside an Alpine Linux Docker container in order to have a user with an UID
matching a specific user on the host.
The problem is that I'm facing adduser: number 1340816314 is not in 0..256000 range
even if I redefine the value of UID_MAX
inside /etc/login.defs
by following adduser man page. I don't think by the way that it has any impact as the adduser
command in Alpine is from BusyBox.
Here is the log of what I try to do:
$ docker run -it --rm alpine:3.4 sh
/ # adduser -D -g '' -u 1340816314 user
adduser: number 1340816314 is not in 0..256000 range
/ # echo "UID_MAX 1340816314" > /etc/login.defs
/ # adduser -D -g '' -u 1340816314 user
adduser: number 1340816314 is not in 0..256000 range
/ # echo "UID_MAX 1340816315" > /etc/login.defs
/ # adduser -D -g '' -u 1340816314 user
adduser: number 1340816314 is not in 0..256000 range
Do you know how to add a user with a large UID
in Alpine Linux inside a Docker container?
Alpine uses the command adduser and addgroup for creating users and groups (rather than useradd and usergroup ). Or alternatively, you can replace the whole snippet above using this: USER 405 which is the guest user within Alpine Linux.
Understanding how user names, group names, user IDs (uid), and group IDs (gid) map between the processes running in the container and the host system is important for building a secure system.
There is a more elegant solution to the high UID/GID in Alpine.
The package shadow
contains the useradd
and groupadd
utilities which in turn supports higher values. Not sure which is the upper bound of those utils and if the whole 2^32 space is supported, but I've tested with values over 600 million and it works.
For example the commands to achieve this would look something like this:
UID=666000666
GID=999000999
apk add shadow
/usr/sbin/groupadd -g ${GID} my_group
/usr/sbin/useradd -s /bin/sh -g ${GID} -u ${UID} my_user
Note that I'm passing the shell variable to useradd
as by default it tries to use /bin/bash
which is not installed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With