在 docker 容器内运行 docker? [英] Run docker inside a docker container?
问题描述
我正在使用 docker 容器来构建我的软件并将其部署到 ec2 的集合中.在部署脚本中,我构建了我的软件,然后将其打包到 docker 映像中.映像被推送到我的私人注册表,由我的生产 ec2 拉取,然后运行.所以基本上我需要在 docker 容器中运行 docker.
I am using a docker container to build and deploy my software to a collection of ec2's. In the deployment script I build my software and then package it in a docker image. The image is pushed to my private registry, pulled by my production ec2's and then run. So essentially I will need to run docker within a docker container.
问题是我实际上无法在我的容器上启动 docker.如果我尝试
The problem is that I can't actually start docker on my container. If I try
service docker start
我明白了
bash: service: command not found
如果我尝试
docker -d
我明白了
2014/10/07 15:54:35 docker daemon: 0.11.1-dev 02d20af/0.11.1; execdriver: native; graphdriver:
[e2feb6f9] +job serveapi(unix:///var/run/docker.sock)
[e2feb6f9] +job initserver()
[e2feb6f9.initserver()] Creating server
2014/10/07 15:54:35 Listening for HTTP on unix (/var/run/docker.sock)
[error] attach_loopback.go:42 There are no more loopback device available.
loopback mounting failed
[e2feb6f9] -job initserver() = ERR (1)
2014/10/07 15:54:35 loopback mounting failed
docker 容器上不存在 service 命令,所以我无法启动 docker.我不确定我现在应该做什么来启动 docker,所以我有点卡在这里,感谢任何帮助.
The service command doesn't exist on the docker container so I can't start docker. I'm not sure what I should be doing now to start docker so I'm a bit stuck here, any help is appreciated.
更多信息
主机正在运行 fedora 20(最终将在 ec2 上运行 amazon linux)
Host machine is running fedora 20 (will eventually be running amazon linux on an ec2)
Docker 容器运行的是 centos 7.0
Docker container is running centos 7.0
主机正在运行 Docker 版本 1.2.0,构建 fa7b24f/1.2.0
Host is running Docker version 1.2.0, build fa7b24f/1.2.0
容器正在运行 docker-0.11.1-22.el7.centos.x86_64
Container is running docker-0.11.1-22.el7.centos.x86_64
推荐答案
如何不运行docker inside docker"并在您的主机上运行 docker,而是从您的 docker 容器内运行?只需挂载您的 docker.sock 和 docker 二进制文件:
How about not running 'docker inside docker' and run docker on your host, but from within your docker container? Just mount your docker.sock and docker binary:
docker run -v/var/run/docker.sock:/run/docker.sock -v $(which docker):/bin/docker [your image]
https://github.com/sameersbn/docker-gitlab 使用这种方法来启动 docker 容器,取看看这张图片.
https://github.com/sameersbn/docker-gitlab uses this approach to spin up docker containers, take a look at this image.
你也可以看看:https://registry.hub.docker.com/u/mattgruter/doubledocker/
2016 年 7 月更新
最新的方法是使用 docker:dind
图像,如下所述:https://hub.docker.com/_/docker/
The most current approach is to use docker:dind
image, as described here:
https://hub.docker.com/_/docker/
简短摘要:
<代码>$ docker run --privileged --name some-docker -d docker:dind
然后:<代码>$ docker run --rm --link some-docker:docker docker info
这篇关于在 docker 容器内运行 docker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!