Docker in docker connection error - docker

I'm trying to run a Java application in a docker container. The application also communicates with docker. So I used docker:latest image and installed the openjdk. Now when I am running the container in interactive mode (privileged) I get the error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? when I input any docker command on the command line.
I run the container with docker run --privileged -ti con_name

Have you gone through this link? In there it's mentioned that /var/lib/docker needs to be a volume. In your docker run command, you are not mentioning any volumes. You might give this page a read and make sure everything is correct.

Related

docker compose inside docker causes error

I am working in a task where I am having to use docker compose inside a docker container. When I perform docker compose --file setup.yaml, I get the following error.
no valid drivers found: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Is there a way to resolve this error?
What I have tried:
I looked at a few documentation on the internet and I am performing a volume mount of the path to socket daemon as follows,
docker run -v /var/run/docker.sock:/var/run/docker.sock -it -d <container_id>
But after this command, the container exits after a while. Not sure if the approach is correct.

Ubuntu test container (ryuk) unable to connect to docker daemon despite docker desktop runnning

I'm getting the following error when I try to run test container in my java app from the IDE:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
however docker desktop is running.
Also I am getting the same error when I run the testcontainers/ryuk image directly from docker desktop by clicking the run button in the images panel.
But the container runs when I use the following command in the terminal:
docker run -i --mount type=bind,source=/var/run/docker.sock,destination=/var/run/docker.sock testcontainers/ryuk:0.3.4
EDIT:
the test container works when I installed docker engine cli and use it as the active context but it's a hassle switching. It seems the default bind being used is cli.
EDIT2:
I've uninstalled and purged every docker installation and reinstalled only docker desktop and it's still the same, on a windows machine it's working properly though.

How to build a docker image in wsl2?

I'm using docker in wsl2. I followed this guide for the setup and everything covered therein seems to work.
Now when I try to build a docker image in wsl2 with docker build . I get the error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I assume that I have to tell docker build on which IP the docker host is running (similar to docker -H 172.20.5.64 run --rm hello-world), but I have no idea how to do this?
I had the same problem, here is the solution, that worked for me:
I had to stop docker
sudo docker service stop
I had to start docker daemon
sudo dockerd
I had to stop docker daemon by pressing ctrl + z
Than i had to move the process in the background
bg %1
Then I was able to restart docker
sudo docker service start
After that, I did no longer get an error.
I hope this works for you too.

Rootless-ly Running Docker Daemon inside another Docker container

According to Docker official website: https://docs.docker.com/engine/security/rootless/ it's possible to run Docker Daemon rootless-ly (without root access, no --privileged flag).
However I'm convinced this would not work when running from inside a Docker container. There is no way of getting modprobe inside a Docker container without root access (--privileged). So it's not possible to install the Docker rootless script.
Supposedly there is an official image in Docker hub: docker:dind-rootless image here So I pulled the image and SSH'd into the container, however I'm getting the following error when running dockerd
INFO[2020-07-17T20:50:32.355617100Z] Starting up dockerd needs to be started with root. To see how to run dockerd in rootless mode with unprivileged user, see the documentation
Any suggestions on how to run Docker daemon rootlessly inside another Docker container? I know this is possible with root, but is there a way to do without? I can't get root access as I'm deploying to AWS fargate, which doesn't support privileged access at the container level.
It's been 2 years. There's an image for it now.
https://docs.docker.com/engine/security/rootless/#rootless-docker-in-docker

GitLab - Docker inside gitlab/gitlab-ce get errors

I'm running a gitlab/gitlab-ce container on docker. Then , inside it, i want to run a gitlab-runner service, by providing docker as runner. And every single command that i run (e.g docker ps, docker container ..), i get this error:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is
the docker daemon running
P.s: i've tried service docker restart, reinstal docker and gitlab-runner.
By default it is not possible to run docker-in-docker (as a security measure).
You can run your Gitlab container in privileged mode, mount the socket (-v /var/run/docker.sock://var/run/docker.sock) and try again.
Also, there is a docker-in-docker image that has been modified for docker-in-docker usage. You can read up on it here and create your own custom gitlab/gitlab-ce image.
In both cases, the end result will be the same as docker-in-docker isn't really docker-in-docker but lets your manage the hosts docker-engine from within a docker container. So just running the Gitlab-ci-runner docker image on the same host has the same result and is a lot easier.
By default the docker container running gitlab does not have access to your docker daemon on your host. The docker client uses a socket connection to communicate to the docker daemon. This socket is not available in your container.
You can use a docker volume to make the socket of your host available in the container:
docker run -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-ce
Afterwards you will be able to use the docker client in your container to communicate with the docker daemon on the host.

Resources