简体   繁体   English

我们可以在一个在Ubuntu 18.04的虚拟盒中运行的docker容器中运行docker吗?

[英]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. 我想在另一个docker容器中运行docker。 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: 我的主容器运行在OS Ubuntu 18.04的虚拟框中,它位于我的Windows 10上。在尝试运行它时,它显示为:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. 无法在unix:///var/run/docker.sock连接到Docker守护程序。 Is the docker daemon running? docker守护程序是否正在运行?

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 在docker网页上检查dind(docker中的docker)如何实现它: 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. 您的错误表明顶级容器中的dockerd未运行或您未在依赖容器上安装docker.sock以与在顶级容器上运行的dockerd进行通信。

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. 我使用这个docker命令在我的Ubuntu虚拟盒中的docker容器中运行电流: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. 在这个docker容器中,我想安装并运行docker,以便我的电子流中的CI / CD管道可以访问并使用docker命令。

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. 根据您的上述描述, ecdocker/eflow-ce是您的CI / CD解决方案容器,您只想在此容器中使用docker command ,然后您不需要解决方案。 You can just access to a container's host docker server. 您只需访问容器的主机docker服务器即可。

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 添加--privileged
  • Add -v $(which docker):/usr/bin/docker , then you can use docker client in container. 添加-v $(which docker):/usr/bin/docker ,然后你可以在容器中使用docker client
  • Add -v /var/run/docker.sock:/var/run/docker.sock , then you can access host's docker daemon using client in container. 添加-v /var/run/docker.sock:/var/run/docker.sock ,然后您可以使用容器中的客户端访问主机的docker守护程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM