Skip to content
Advertisement

Using `groupadd` in Docker container

I’m using Ubuntu 14.04 Trusty Tahr, and a quick peek at /etc/group reveals

$ cat /etc/group
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:syslog
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
kmem:x:15:
dialout:x:20:
fax:x:21:
voice:x:22:
cdrom:x:24:
floppy:x:25:
tape:x:26:
sudo:x:27:
audio:x:29:
dip:x:30:
www-data:x:33:
backup:x:34:
operator:x:37:
list:x:38:
irc:x:39:
src:x:40:
gnats:x:41:
shadow:x:42:
utmp:x:43:
video:x:44:
sasl:x:45:
plugdev:x:46:
staff:x:50:
games:x:60:
users:x:100:
nogroup:x:65534:
libuuid:x:101:
netdev:x:102:
crontab:x:103:
syslog:x:104:
ntp:x:105:
ssh:x:106:

When I tried to add staff, I got an error message as I would expect (being that staff is already defined with gid 50).

$ groupadd --gid 20 --non-unique staff
groupadd: group 'staff' already exists

The unexpected part is when I tried to add a user with the staff group.

$ useradd --groups staff --no-create-home --no-user-group --non-unique --root /projects/ --uid 502 username
useradd: group 'staff' does not exist

What am I doing wrong here? It don’t believe it is Docker specific, but I just wanted to make mention in case it was important.

Advertisement

Answer

Your problem is the use of the --root argument. If you look at the useradd man page, you’ll note that --root specifies a chroot directory:

-R, --root CHROOT_DIR
           Apply changes in the CHROOT_DIR directory and use the configuration
           files from the CHROOT_DIR directory.

That means that when you pass --root projects, the useradd command will be looking for /projects/etc/passwd, /projects/etc/group, etc. Those don’t exist, which leads to the “does not exist” error.

I wonder if you actually meant --home-dir or --base-dir instead of --root?

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement