Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a container user to a user group in the Docker host?

Tags:

linux

docker

I'm currently experimenting on Docker specifically on the aspect where a user inside given container affects the Docker host itself. Ultimately, I want the user to be able to run containers on its very own host from inside its container. It kind of sounds a little absurd, but I'm hoping it works.

At the moment, I'm looking for a way for that given user to be part of the Docker host's docker group. Is there a way to do that?

like image 850
Psycho Punch Avatar asked Feb 26 '16 19:02

Psycho Punch


People also ask

How do I add a user to a container?

To create a common user, you must be connected to the root. You can optionally specify CONTAINER = ALL , which is the default when you are connected to the root. To create a local user, you must be connected to a PDB. You can optionally specify CONTAINER = CURRENT , which is the default when you are connected to a PDB.

How do I run a Docker container as a different user?

Running Commands as a Different User in a Docker Container To run a command as a different user inside your container, add the --user flag: docker exec --user guest container-name whoami.

Can multiple users connect to the same Docker container?

Multiple users on the same host can use docker.


1 Answers

From the perspective of the Docker host, any users inside the container are treated exactly the same as a user outside the container with the same UID (not the same name!), regardless of whether the UID is actually in use on the host. Unfortunately, it appears that only users with a username can belong to groups, so you can't just add the UID to the group. Instead, you need to add the host user with the same UID to the group (or create a user with that UID if one doesn't exist).

like image 120
jwodder Avatar answered Sep 28 '22 16:09

jwodder