2

When I access my container:

jenkins@bc145b8cfc1d:/$ docker ps

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

jenkins@bc145b8cfc1d:/$ whoami
jenkins
jenkins@9cdb24cf71f2:/$ usermod -G users jenkins
ERROR : usermod: Permission denied.**
StephenKing
  • 36,187
  • 11
  • 83
  • 112
Isha Gusai
  • 21
  • 2
  • You're running these commands in a container? Is Docker in the container? Have you mounted the Docker socket? – johnharris85 Jan 10 '17 at 20:18
  • Jenkins is running in a container and docker is in host machine.we are trying to run docker commands from jenkins container and we have already mounted the docker socket. – Isha Gusai Jan 11 '17 at 05:47
  • Possible duplicate of [How to mount docker socket as volume in docker container with correct group](http://stackoverflow.com/questions/36185035/how-to-mount-docker-socket-as-volume-in-docker-container-with-correct-group) – eawenden Jan 11 '17 at 14:10

1 Answers1

1

You can execute a bash command inside a container as a different user. In this case you can run from your host:

docker exec -it --user root <container id> usermod -G users jenkins

or you can enter the container interactively and execute any commands as root as follows:

docker exec -it --user root <container id> bash

and then:

root@9cdb24cf71f2:/$ usermod -G users jenkins

Note: The solution above assumes that the group users exists.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
Mark
  • 5,437
  • 2
  • 19
  • 29