Docker Community Forums

Share and learn in the Docker community.

[solved] Using docker inside another container


(Malikoth) #1

I’ve gotten quite fond of using the advice from this post: https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/

He says you can use docker from inside another docker container by starting it with -v /var/run/docker.sock:/var/run/docker.sock

Does Docker for Windows beta have anything I can do to achieve a similar result?


Where is the file docker.sock?
Unable to run Docker from inside Docker
(Malikoth) #2

The answer is yes, you can use the exact same procedure, bind-mounting the exact same socket as on Linux or Mac, to achieve exactly the same effect. I apologize for posting before I actually tried it out!


(Henr7) #3

But how? I need to find /var/run/docker.sock on my windows machine in order to do this.
What I want to do is use this to ssh into my containers:

I cannot figure out how.

Henry


(Malikoth) #4

You have to understand the structure of what Docker for Windows provides. It uses the Windows hypervisor that was introduced (and only available) in Windows 10 to run a VM. I believe it’s Alpine Linux running in that VM, but I’m by no means certain. That VM is what runs the Docker client, contains the images and containers, etc. The whole point of Docker for Windows is to make this process transparent and easy to utilize, but its success here has lead to some confusion, as you and I have both experienced.

So /var/run/docker.sock exists inside of the Linux VM, not anywhere on your Windows computer. There’s also a command-line client that is installed in Windows-land that passes commands to the VM, and outputs data that it gets back from it. When you tell it to mount the docker socket from your Windows command line, it doesn’t really do anything in Windows. The command is passed to the VM, which then mounts the socket for access by the containers.

Barring other problems with your installation or Docker itself, you should be able to run the “docker run” command suggested in the docker-ssh project readme without issue. If that’s not the case, post the error you’re getting and then we can try to resolve it.


(Henr7) #5

Actually I do not see any error.
I try for instance:

PS C:\Users\henry> docker run -d -p 2222:22 -v /var/run/docker.sock:/var/run/docker.sock -e CONTAINER=mysql -e AUTH_MECHANISM=noAuth jeroenpeeters/docker-ssh

Container is created and running. But when I try to connect with ssh on Port 2222 I get Connection refused.

When I connect to the docker-ssh-container I can see /var/run/docker.sock:

PS C:\Users\henry> docker exec -it nauseous_swanson sh
/src # cd /var/run/
/var/run # ls
docker.sock
/var/run # cat docker.sock
cat: can't open 'docker.sock': No such device or address
/var/run # ls -lias
total 8
     22      4 drwxr-xr-x    2 root     root          4096 Nov 25 10:04 .
     21      4 drwxr-xr-x   13 root     root          4096 Nov 25 10:04 ..
  12787      0 srw-rw----    1 root     50               0 Nov 18 09:21 docker.sock
/var/run #

(Malikoth) #6

Yup, that’s about what I expected to see. So, troubleshooting an SSH connection refused error is your next step, and there’s a lot of good posts on the topic on Ubuntu forums, and Stack Overflow. Google is your friend. If the problem is specific to the docker-ssh project, raise the issue with the maintainer. I think it more likely that there’s a configuration problem somewhere with your system.


(Wangfugen) #7

Thanks ~ You really have helped me.
I have found the problem and try to solve it.
Finally after your tips, I found it is not a problem.
Just mount /var/run/docker.sock to our container is OK!
Haha, we want to solve a problem which is not a real problem.


(Jan1torearl) #8

After a day lost trying to simulate my CI environment I came across this. Thank you, thank you!! Simply adding another -v /var/run/docker.sock:/var/run/docker.sock volume to my docker run command allowed the Docker daemon to magically run inside the parent container!