docker "Unable to find group docker" using "--group-add docker"

Viewed 2691

I would like to know why --group-add docker in the following doesn't work.But I have another priority image that it does work.

docker run \
    --rm \
    -it \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /etc/docker/daemon.json:/etc/docker/daemon.json \
    -v /etc/shadow:/etc/shadow \
    -v /etc/passwd:/etc/passwd \
    -v /etc/sudoers:/etc/sudoers \
    -v /etc/group:/etc/group \
    -u $(id -u):$(id -g) \
    --group-add docker \
    docker/compose:debian-1.27.4 \
    bash

it errors out

docker: Error response from daemon: Unable to find group docker.

I have the same issue with other images like ubuntu, hello-world and so on. What is needed in the image to be able to add docker group?

My system:

  • Ubuntu 18.04
  • docker 19.03.13

I know I have the docker group in the host. I can see it in the output of groups.

1 Answers

With you command, you are trying to add current user to the group docker, but inside docker, not in the host.

As group docker does not exist inside docker, reason why you've got error message.

If it's really what you want, you can use groupadd docker to create the group, then add the user to the group.

Related