Docker ps giving permission issues - docker

Issue for
http:///var/run/docker.sock/v1.19/containers/json: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?

I got the solution for this
Add the login user for ssh let's say gse to the docker group
sudo usermod -aG docker "gse"
then restart the vm using sudo reboot
and do docker ps and it works :-)

Try to use with root user or add your user in docker group.

Related

Docker sudo permissions

I am able to run docker without sudo but after sometimes it again asks for permissions and I am not able to Attach container in VS code
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/json: dial unix /var/run/docker.sock: connect: permission denied
To sort out permission errors and to run containers, check the following command
sudo chmod 666 /var/run/docker.sock

Jenkins agent on GKE failed to run docker dial unix /var/run/docker.sock: connect: permission denied

I'm running Jenkins helm on GKE standard cluster with Container-Optimized OS with Docker (cos) image.
I'm running jenkins agent with docker installed and jenkins user added to docker group. I'm mounting /var/run/docker.sock as volume .. also tried t run with UID 1000.
-v /var/run/docker.sock:/var/run/docker.sock
But still getting dial unix /var/run/docker.sock: connect: permission denied ?! Any idea what I'm missing here ?
In addition to #again comment, below are possible reasons to look for regarding pemission denied error:
Docker is not installed on host
UID 1000 does not have permission to /var/run/docker.sock (try to chmod 777 the file temporarily and reduce permssion as needed)
Check Host and Container docker ID, must have the same UID
Also, you can refer on related links below for possible answers.
Docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
Run Docker as jenkins-agent, in a docker-container, as non-root user
Use docker inside docker with jenkins user #263
docker.sock permission denied

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post

I’ve just run Dockerfile in jenkins setup then I get the following error:
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.40/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=2quv9npfhvxjco1lqvt8aea9h&shmsize=0&t=testfile&target=&ulimits=null&version=1: dial unix /var/run/docker.sock: connect: permission denied
.
..
Dockerfile
WebApp.war
SSH: EXEC: completed after 404 ms
SSH: Disconnecting configuration [Docker] ...
SSH: Transferred 1 file(s)
Finished: SUCCESS
docker.deamon tell us this:
The Docker daemon binds to a Unix socket instead of a TCP port. By
default that Unix socket is owned by the user root and other users can
only access it using sudo. The Docker daemon always runs as the root
user.
If you don’t want to preface the docker command with sudo, create a
Unix group called docker and add users to it. When the Docker daemon
starts, it creates a Unix socket accessible by members of the docker
group.
Check if the docker group already exists:
cat /etc/group | grep docker
if it doesn't, create with this command:
sudo groupadd docker
add the jenkins user to docker group:
sudo usermod -a -G docker jenkins-user
newgrp docker
Check if is it worked...
$ cat /etc/group | grep docker
docker:x:***:jenkins-user
Restart the jenkins
logout, and login again
Or you can just try run the docker with sudo.

Azure DevOps with self-hosted Ubuntu machine: docker fails

I created an Azure DevOps agents based on the Ubuntu image that can be found here: https://github.com/Microsoft/azure-pipelines-image-generation
After I deployed the machine and installed the agent (see https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-linux?view=vsts) I ran a Docker task and got the following error:
dial unix /var/run/docker.sock: connect: permission denied
What do I have to do to get the Docker task executed successfully?
The problem is that the agent service has not the permissions to connect. You can either run the agent service as root (sudo ./svc.sh install root) what I would not recommend or add the user to the Docker group via sudo usermod -a -G docker $USER.
Then logout and and log in again and it should work.
See also https://docs.docker.com/install/linux/linux-postinstall/

How to use docker from inside Jenkins docker container

I'm facing the following problem: I created a Jenkins docker container, and linked the docker socket on the host, with the container. Like this:
docker run -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 -p 50000:50000 -d --name jenkins --restart unless-stopped jenkins
Then when I try to create some jobs on jenkins I get the usual "permission denied" message:
Got permission denied while trying to connect to the Docker daemon
socket at unix:///var/run/docker.sock: Get
http://%2Fvar%2Frun%2Fdocker.sock/v1.29/images/json: dial unix
/var/run/docker.sock: connect: permission denied
But that problem doesn't happen if I attach to the container and run the command using the root user.
How can I fix this?
I can't add jenkins user to docker group on the host by running sudo gpasswd -a jenkins docker (because there is no jenkins user on the host, only in the container) and I also can't run this command inside the container (because the container doesn't know about any docker group). Any tips on how to solve this?
You can add the docker group inside the container. Do this in its bash:
groupadd -g <docker-group-id> docker
Find out the <docker-group-id> running this in the host:
ls -ln /var/run/docker.sock
Then add the jenkins user to the docker group:
gpasswd -a jenkins docker
Take into account any security issue that this could produce:
Warning: The docker group grants privileges equivalent to the root user. For details on how this impacts security in your system, see Docker Daemon Attack Surface.
Refer to the docs

Resources