How to get access to the docker cmd from docker container? - docker

I've tried to get access to docker command from a container I got an issue says that
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
the container created using this CMD line :
sudo docker run -p 8080:8080 -p 50000:50000 -v /var/run/docker.sock:/usr/lib/systemd/system/docker.socket --name jenkins-master -d jenkins

Hey Guys the issue was in the socket volume I mean in this section
-v /var/run/docker.sock:/usr/lib/systemd/system/docker.socket
should be change to
-v /var/run/docker.sock:/var/run/docker.sock

Related

How to create a Debian docker container that can run docker containers?

I need a Debian container that can run containers itself (and has access to systemd). Following this post, I have tried to run
docker run -v /var/run/docker.sock:/var/run/docker.sock --name debian-buster-slim -h 10-slim -e LANG=C.UTF-8 -it debian:10-slim /bin/bash -l
but the container cannot run docker containers. What am I doing wrong?

docker container fail to connect to docker daemon if use /usr/sbin/init to start the container

sudo docker run -it --name="cms_docker_without_init_with_port" --privileged=true --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /home/cms/iris4_build:/home/cms/iris4_build -v /home/cms/jenkins:/home/cms/jenkins -v /home/cms/bin:/home/cms/bin -v /home/cms/cmn:/home/cms/cmn -v /home/cms/wls/bin:/home/cms/wls/bin -v /etc/passwd:/etc/passwd -v /etc/group:/etc/group -p 22000:22 artifact.oocl.com/fwk/cms_docker:1
I use above command to start the docker container, the cms_docker CAN connect to docker daemon in target VM.
There is contos7 inside the container, and I want to start the sshd service. I found in the docker official document, have to add /usr/sbin/init when start the container.
https://github.com/docker-library/docs/tree/master/centos#dockerfile-for-systemd-base-image
So I add the "/usr/sbin/init" when start the container. The command is below:
sudo docker run -it --name="cms_docker_without_init_with_port" --privileged=true --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /home/cms/iris4_build:/home/cms/iris4_build -v /home/cms/jenkins:/home/cms/jenkins -v /home/cms/bin:/home/cms/bin -v /home/cms/cmn:/home/cms/cmn -v /home/cms/wls/bin:/home/cms/wls/bin -v /etc/passwd:/etc/passwd -v /etc/group:/etc/group -p 22000:22 artifact.oocl.com/fwk/cms_docker:1 /usr/sbin/init
But after I added /usr/sbin/init to start container, the cms_docker cannot connect to the docker daemon.
enter image description here
I need to start the sshd service and also need cms_docker connect to docker daemon. But now it seems there is conflict. Do you have any idea to solve this?

Unable to access Docker Daemon from Jenkins

I am running Jenkins inside a docker container.
I use the following command to start the container -
docker run -p 8080:8080 -p 50000:50000 -v "${PWD}:/var/jenkins_home" -v /var/run/docker.sock:/var/run/docker.sock aemdesign/jenkins
Notice -v /var/run/docker.sock:/var/run/docker.sock - I have done this so that I can access the docker daemon from within Jenkins as per this article.
I cd into the jenkins container using docker exec -it <mycontainer> bash
I then run docker ps -a but I still get docker command not found error.
I did some more research online and found out about the docker plugin for Jenkins, and configured it to connect to the docker daemon. I get the following error
Am I missing something? How do I solve this issue? Please note that I am doing this locally on a MAC machine.
-v /var/run/docker.sock:/var/run/docker.sock, this just means your container has ability to access docker daemon on the host, not mean your container will have the docker client.
You could use -v $(which docker):/usr/bin/docker to add docker client to your container, then you will find the command.
docker run -u root -p 8080:8080 -p 50000:50000 -v $(which docker):/usr/bin/docker -v "${PWD}:/var/jenkins_home" -v /var/run/docker.sock:/var/run/docker.sock aemdesign/jenkins
Another way if you want reserve jenkins user.
docker run -u jenkins:$(cut -d: -f3 < <(getent group docker)) -p 8080:8080 -p 50000:50000 -v $(which docker):/usr/bin/docker -v "${PWD}:/var/jenkins_home" -v /var/run/docker.sock:/var/run/docker.sock aemdesign/jenkins

Can we run docker inside a docker container which is running in a virtual-box of Ubuntu 18.04?

I want to run docker inside another docker container. My main container is running in a virtualbox of OS Ubuntu 18.04 which is there on my Windows 10. On trying to run it, it is showing me as:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
How can I resolve this issue?
Yes, you can do this. Check for dind (docker in docker) on docker webpage how to achieve it: https://hub.docker.com/_/docker
Your error indicates that either dockerd in the top level container is not running or you didn't mount docker.sock on the dependent container to communicate with dockerd running on your top-level container.
I am running electric-flow in a docker container in my Ubuntu virtual-box using this docker command: docker run --name efserver --hostname=efserver -d -p 8080:8080 -p 9990:9990 -p 7800:7800 -p 7070:80 -p 443:443 -p 8443:8443 -p 8200:8200 -i -t ecdocker/eflow-ce. Inside this docker container, I want to install and run docker so that my CI/CD pipeline in electric-flow can access and use docker commands.
From your above description, ecdocker/eflow-ce is your CI/CD solution container, and you just want to use docker command in this container, then you did not need dind solution. You can just access to a container's host docker server.
Something like follows:
docker run --privileged --name efserver --hostname=efserver -d -p 8080:8080 -p 9990:9990 -p 7800:7800 -p 7070:80 -p 443:443 -p 8443:8443 -p 8200:8200 -v $(which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -i -t ecdocker/eflow-ce
Compared to your old command:
Add --privileged
Add -v $(which docker):/usr/bin/docker, then you can use docker client in container.
Add -v /var/run/docker.sock:/var/run/docker.sock, then you can access host's docker daemon using client in container.

Docker: tendermint container not work

My OS is Windows 10 and docker version 17.12.0-ce, build c97c6d6.
Here is my plan:
0. Get containers
docker pull tendermint/tendermint
docker pull tendermint/monitor
1. Init container
docker run --rm -p 46657:46657 --name tendermint_bc -v "C:/Users/user/sandbox/tendermind/tmdata:/tendermint" tendermint/tendermint init
2. Start container
docker run --rm -d -v "C:/Users/user/sandbox/tendermind/tmdata:/tendermint" tendermint/tendermint node --proxy_app=dummy
3. Start tendemint monitor
docker run -it --rm --link=tm tendermint/monitor tendermint_bc:46657
By start of tendermint container I see only one hash, but by docker ps -a container is not listed.
If I run docker logs tendermint_bc, result is:
Error response from daemon: No such container: tendermint_bc
Same workflow on Unix work fine.
Thx for help.
In step 1, you are initializing Tendermint, but not running it. To run it, execute:
docker run --rm -p 46657:46657 --name tendermint_bc -v "C:/Users/user/sandbox/tendermind/tmdata:/tendermint" tendermint/tendermint node --proxy_app=dummy

Resources