Docker create network on WSL - docker

I am using windows WSL. Have started a docker on windows and exposed the port for WSL using option Expose daemon on tcp://localhost:2375 without TLS
in .bashrc
export DOCKER_HOST=tcp://localhost:2375
My all other docker commands are working fine. But when I try to create a network it fails
sudo docker network create mynetwork
with error
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

During installing of docker etc. I followed a tutorial which gives sudo access for docker.
sudo usermod -aG docker $USER
so sudoing again is not working. Without sudo the command is working good.
docker network create mynetwork

Related

how can i made docker work with my user (ubuntu)

this is the current situation:
hamsterofdeath#HodVm:~$ docker ps
Cannot connect to the Docker daemon at unix:///home/hamsterofdeath/.docker/desktop/docker.sock. Is the docker daemon running?
hamsterofdeath#HodVm:~$ sudo docker ps
[sudo] password for hamsterofdeath:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
hamsterofdeath#HodVm:~$ docker ps
Cannot connect to the Docker daemon at unix:///home/hamsterofdeath/.docker/desktop/docker.sock. Is the docker daemon running?
hamsterofdeath#HodVm:~$ sudo groupadd docker
groupadd: group 'docker' already exists
hamsterofdeath#HodVm:~$ sudo gpasswd -a ${USER} docker
Adding user hamsterofdeath to group docker
hamsterofdeath#HodVm:~$ docker ps
Cannot connect to the Docker daemon at unix:///home/hamsterofdeath/.docker/desktop/docker.sock. Is the docker daemon running?
hamsterofdeath#HodVm:~$
cat /etc/group gives me "docker:x:996:hamsterofdeath"
logging out and in again changes nothing. i also tried:
sudo usermod -aG docker $USER
sudo usermod -a -G docker $USER
but it has no effect. what do i need to do?
i always get:
Cannot connect to the Docker daemon at unix:///home/hamsterofdeath/.docker/desktop/docker.sock. Is the docker daemon running?
or
Error response from daemon: dial unix /home/hamsterofdeath/.docker/desktop/docker.raw.sock: connect: connection refused
with sudo, it works
there might be another(?) problem
i removed docker via
sudo apt remove docker
but the "docker" command still exists.
amsterofdeath#HodVm:~$ sudo apt remove docker
[sudo] password for hamsterofdeath:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package 'docker' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
hamsterofdeath#HodVm:~$ docker ps
Cannot connect to the Docker daemon at unix:///home/hamsterofdeath/.docker/desktop/docker.sock. Is the docker daemon running?
hamsterofdeath#HodVm:~$
Waht you could try:
Try restarting the bash process and probably the machine.
See if the docker group is associated with the .sock file
This should return nothing:
stat -c %U:%G /home/hamsterofdeath/.docker/desktop/docker.raw.sock | grep -v root:docker
if it does do:
chown root:docker /home/hamsterofdeath/.docker/desktop/docker.raw.sock
Is $USER filled with the correct data ?
Restart docker engine using sudo systemctl
Else go to Post-Install and try all the steps there especially since it seems to an VM restart it
Next Docker Desktop is rather sketchy. I personally recommend using the VS-Code Docker extension as it offers almost the same functionality as docker desktop and works fine with Ubuntu. See Docker Extension VS-Code

Intellij Idea: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Even though my user is on docker group and I can launch docker without sudo, and I'm running idea.sh from my user, whenever I try to connect to docker from within Intellij Idea docker plugin, I get
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I'm trying the Unix socket method. I already tried multiple restarts and logout.
I'm on Ubuntu 20.04 and Intellijd Idea 2020.3
Adding current user to docker group worked for me:
sudo gpasswd -a ${USER} docker
You might need to create group first:
sudo groupadd docker
restart your OS after those changes
For me it work
sudo chmod 0777 /var/run/docker.sock
Then test this in the terminal without the sudo
docker ps -a
normally you should have access to the docker process

jenkins in docker - Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I'm running https://hub.docker.com/r/jenkinsci/blueocean/ in docker. Trying to build a docker image in jenkins.
but i get the following error:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
clearly the jenkins version in docker does not have access to the docker binary.
I confirmed this by,
docker exec -it db4292380977 bash
docker images
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
"db4292380977" is the running container. It shows the same error.
Question:
how do I allow access to docker in the jenkins container?
The docker client is installed on the jenkinsci/blueocean image, but not the daemon. Docker client will use the daemon (by default via the socket unix:///var/run/docker.sock). Docker client needs a Docker daemon in order to work, you can read Docker Architecture for more info.
What you can do:
Use docker-in-docker (DinD) image
Library Docker image provides a way to run a Docker daemon in Docker, you can then use it from another container. For example, using plain docker CLI:
docker run --name docker-dind --privileged -d docker:stable-dind
docker run --name jenkins --link=docker-dind -d jenkinsci/blueocean
docker exec jenkins docker -H docker-dind images
REPOSITORY TAG IMAGE ID CREATED SIZE
Docker daemon runs in docker-dind container and can be reached using the same hostname. You just need to provide the docker client with the daemon host (-H docker-dind in the example, you can also use DOCKER_HOST env variable as described in the doc).
Mount host machine /var/run/docker.sock in your container
As described by #Herman Garcia answer:
docker run -p 8080:8080 --user root \
-v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean
You need to mount your local /var/run/docker.sock and run the container as root user
NOTE: this might be a security flaw so be careful who has access to the jenkins container
docker run -p 8080:8080 --user root \
-v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean
you will be able to execute docker inside the container
➜ ~ docker exec -it gracious_agnesi bash
bash-4.4# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
c4dc85b0d88c jenkinsci/blueocean "/sbin/tini -- /usr/…" 18 seconds ago Up 16 seconds 0.0.0.0:8080->8080/tcp, 50000
/tcp gracious_agnesi
Just only try to do the same command but with sudo in the beginning
For example
sudo docker images
sudo docker exec -it db4292380977 bash
To avoid use sudo in the future you should run this command in Unix O.S
sudo usermod -aG docker <your-user>
Change for the user that you are using at this moment. Remember to log out and back in for this to take effect! More information about Docker installation click here

Docker in Docker(DND) is not starting

I have a simple Ubuntu 16.10 container which has docker.io installed.
The docker process terminates after it starts and log has this information. Any troubleshooting suggestions?
$ docker run -it --name dcos-ubuntu-python5 python-docker /bin/bash
root#5ff6bb6b6dc7:/# docker run hello-world
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.
root#5ff6bb6b6dc7:/# service docker start
* Starting Docker: docker [ OK ]
root#5ff6bb6b6dc7:/# service docker status
* Docker is not running
root#5ff6bb6b6dc7:/# tail -f /var/log/docker.log
time="2017-12-21T17:09:45.464736873Z" level=info msg="libcontainerd: new containerd process, pid: 50"
time="2017-12-21T17:09:46.472578239Z" level=fatal msg="Error starting daemon: error initializing graphdriver: operation not permitted"
Why do you want to run docker within docker container?
Docker-in-Docker is developed to help docker development. And it needs --privileged flag to run docker container.(Please read jpetazzo's blog here.)
If you really want to execute docker in docker container, you also have other options.
Bind mount docker.sock. Some people call this DooD(Docker-outside-of-Docker)
docker run -v /var/run/docker.sock:/var/run/docker.sock ...
Install docker(client) and specify DOCKER_HOST to access remote docker daemon. Be careful about socket protection with certificates.
Are you running docker as sudo if not run as sudo or
Else add user group to docker
docker group. For this run following command:
sudo usermod -aG docker $USER
The answer was simple.
docker run -it --privileged --name dcos-ubuntu-python5 python-docker /bin/bash
(This was also mentioned partly in #SunghoMoon's response. So Credits to him).

run docker Rstudio server without root?

I just started playing with docker. The first thing I did was to install it, and then install Rstudio-server. (I'm running ubuntu 14.04)
sudo apt-get install docker.io
sudo docker run -d -p 8787:8787 -e USER='some_user_name' -e PASSWORD='super_secret_password' rocker/hadleyverse
Is it possible to run a docker rstudio server without sudo? If so, how?
Thanks!
From this answer:
The docker manual has this to say about it:
Giving non-root access
The docker daemon always runs as the root user, and since Docker version 0.5.2, 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 so, by default, you can access it with sudo.
Starting in version 0.5.3, if you (or your Docker installer) create a Unix group called docker and add users to it, then the docker daemon will make the ownership of the Unix socket read/writable by the docker group when the daemon starts. The docker daemon must always run as the root user, but if you run the docker client as a user in the docker group then you don't need to add sudo to all the client commands. As of 0.9.0, you can specify that a group other than docker should own the Unix socket with the -G option.
Warning: The docker group (or the group specified with -G) is root-equivalent; see Docker Daemon Attack Surface details.
Example:
Add the docker group if it doesn't already exist.
sudo groupadd docker
Add the connected user "${USER}" to the docker group. Change the user name to match your preferred user.
sudo gpasswd -a ${USER} docker
Restart the Docker daemon:
sudo service docker restart
If you are on Ubuntu 14.04 and up use docker.io instead:
sudo service docker.io restart
You need to log out and log back in again if you added the current logged in user.

Resources