Permission issue using remote development extension to attach to a docker image - docker

I have added current user to docker group and I'm able to run docker commands like docker run hello-world in terminal opened in vscode with no problem, but vscode doesn't let me attach to a running container, giving "current user does not have permission to run docker. Try adding the user to the 'docker' group" error message.
My system is Ubuntu 18.04, VS code is 1.39.0-insider

If you've not already created a docker group
sudo groupadd docker
Then
sudo usermod -aG docker $USER
Then log out and back in (or reboot) again.

Had the same issue. The reason for the problem was that the vscode server was still running with the old user privileges (without the docker group). Kill the respective process on the remote machine, then reload your vscode windows and everything should work without a reboot.
$ ps aux|grep bin/code-server # find out process id
$ kill <process id>

Related

Docker Desktop in Ubuntu not showing containers those are build with sudo privilege

I build and run an Docker Container using sudo privilege to do so I ran bellow commands
This command to build the container and its build successfully.
sudo docker build -t getting-started .
After that I ran the docker container using bellow command
sudo docker run -dp 3000:3000 getting-started
After running the docker container everything is running fine and I am able to see my container when I ran bellow command
sudo docker ps
But the problem is I am not able to see my container that I just built and ran in my Docker Desktop.
Note: If I build and run the docker container without sudo privilege then I am able to see the container in Docker Desktop.
So now what should I do to manage my containers using Docker Desktop those are build and running using sudo privilege.
i am facing the same problems for a while and didn't get anything that worked for me as of yet but maybe in your case if you can enable docker to run in rootless mode or add your user to docker group enable privileges to enable the user to use docker with out sudo it may also work for the docker desktop to access those images in the sudo mode.
try
https://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo
https://docs.docker.com/engine/install/linux-postinstall/
the other solution i thought up is to make the docker desktop use the context you are using for the docker engine which is the default not the desktop-linux it will create when its starting up maybe that will enable it to read the past containers you were using
or another solution is to run the docker desktop in sudo mode i dont know how to do that as of yet but its worth a shot if you can find out how
if your build successed you can run
docker ps -a
to see all the working and stoped containers
and you can run
docker logs --tail=50 container-name
so you can see the container logs and start fixing the issue

Failed to connect. Is Docker running? (Vs Code)

I get this error in Ubuntu in vscode and I can't see my images in vscode.
I run sudo docker ps -a and everything is OK on terminal!
What should I do to solve this problem?
I think it can be because your user is not in the docker group.
Easily check the list of your user's groups using:
groups <user>
And check in the output if you can see "docker".
If not, simply add the user to the docker group by typing:
sudo usermod -aG docker ${USER}
Don't forget to restart the VS Code and the system if necessary.
I had to create docker group for themozel's solution to work.
Here is what worked for me:
Creates docker group
sudo groupadd docker
Add your user to the docker group
sudo usermod -aG docker $USER
The problem is docker is running as root but vs code trying to connect in user.
I am also having this problem.
I solved this problem with install the Docker Engine
Delete the docker completely
sudo apt-get remove docker docker-engine docker.io containerd runc
Then install the Docker Engine
https://docs.docker.com/engine/install/
With the docker extension installed, workaround for me (on Mac) was:
(cmd-shift-p)
Go to "Preferences: Open Workspace Settings"
at the top of the settings, search for "docker path"
enter Absolute path to docker client executable (in my case "/usr/local/bin/docker")
Hope this helps someone.
In you installed VS Code with the flatpak package manager (For example on PopOS) it will not detect docker

Jenkins: How can Jenkins simulate a log out and log back in?

In order to fix a docker issue in Jenkins, I need to run the following commands:
$ sudo usermod -aG docker tomcat #add the tomcat user to the docker group
$ sudo service docker restart #restart the docker service
The next step is to log out of the session (close the terminal window) and log back in (re-open the terminal window). This is easy from an actual terminal window, but how do we instruct Jenkins to simulate a logout and log back in?
It looks like you are trying to configure your user to access the docker socket. The restart of the engine isn't needed, nor is it necessary to exit the shell:
$ sudo usermod -aG docker tomcat #add the tomcat user to the docker group
$ newgrp docker #recognize the new group membership

Make Jenkins run docker without sudo

I would like to run Docker shell commands on Jenkins like:
docker ps
Is it possible to do it with out using any plugins? Since Jenkins isn't a user, but a service account how can I add to docker group?
First execute
sudo groupadd docker
Then execute
sudo usermod -aG docker $USER
Then logout its important to logout because your group membership is re-evaluated
Login and try again
docker ps
It works!
Following approach worked for me to run docker commands without any plugins
Rather than adding jenkins user to docker group, allowed jenkins user to run sudo commands with out prompting for password and then created an alias to avoid sudo in Dockerfile for jenkins slave. I had to install docker client in the container which connects to daemon running in the host machine.
## allowing jenkins user to run sudo commands
RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
## avoid typing sudo in command line
RUN echo "alias docker='sudo docker '" >> /home/jenkins/.bashrc
(Taken from this answer: https://askubuntu.com/a/477554)
If you run on Ubuntu and Jenkins runs directly on the host machine (i.e. not inside a Docker container):
Add the docker group if it doesn't already exist:
sudo groupadd docker
Add the user "jenkins" to the docker group:
sudo gpasswd -a jenkins docker
Restart the Docker daemon:
sudo service docker restart
Either do a newgrp docker or log out/in to activate the changes to groups.
I had the issue when I was running from jenkins pipeline. I added jenkins user to docker group, restarted the docker engine and rebooted the machine as well. However I still get the same error dial unix /var/run/docker.sock: connect: permission denied.
Finally I added jenkins to root group and it resolved my issue (ubuntu 18.04) (VM on Azure)
sudo gpasswd -a jenkins root
sudo service docker restart

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

I am trying to run my Docker commands, but I am facing the notification error in the title. I tried running:
ps auxww | grep docker
but still getting the error. Any solution?
If you can verify that the docker daemon is running then it may be that your user is not allowed to access docker.
To do this add yourself to the docker group.
sudo usermod -aG docker <userid>
Remember to do a re-login or otherwise apply/activate the new group permission.
newgrp docker
How about launching the daemon
sudo service docker start
should do the trick.
Or
sudo docker -d
In my case I had multiple docker instances running so it didn't know what to attach to. After killing them and restarting, my problem was solved.

Resources