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容器来构建和部署我的软件到ec2的集合。在部署脚本中,我构建了我的软件,然后将其打包在docker镜像中。图像被推送到我的私人注册表,由我的生产ec2's拉动,然后运行。所以基本上我需要在docker容器中运行docker。
The problem is that I can't actually start docker on my container. If I try
问题是我实际上无法在我的容器上启动docker。如果我试试
service docker start
I get
我明白了
bash: service: command not found
And if I try
如果我尝试
docker -d
I get
我明白了
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
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.
docker容器上不存在service命令,因此无法启动docker。我不知道我现在应该做什么来启动码头工具所以我有点卡在这里,任何帮助都表示赞赏。
A bit more information
更多信息
Host machine is running fedora 20 (will eventually be running amazon linux on an ec2)
主机正在运行fedora 20(最终将在ec2上运行amazon linux)
Docker container is running centos 7.0
Docker容器正在运行centos 7.0
Host is running Docker version 1.2.0, build fa7b24f/1.2.0
主机运行Docker 1.2.0版,构建fa7b24f / 1.2.0
Container is running docker-0.11.1-22.el7.centos.x86_64
Container正在运行docker-0.11.1-22.el7.centos.x86_64
3 个解决方案
#1
39
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 in docker'并在docker容器中运行docker?只需挂载docker.sock和docker二进制文件:
docker run -v /var/run/docker.sock:/run/docker.sock -v $(which docker):/bin/docker [your image]
docker run -v /var/run/docker.sock:/run/docker.sock -v $(哪个docker):/ bin / docker [你的形象]
https://github.com/sameersbn/docker-gitlab uses this approach to spin up docker containers, take a look at this image.
https://github.com/sameersbn/docker-gitlab使用这种方法来启动docker容器,看看这个图像。
You can also take a look at: https://registry.hub.docker.com/u/mattgruter/doubledocker/
您还可以查看:https://registry.hub.docker.com/u/mattgruter/doubledocker/
UPDATE on july 2016
2016年7月更新
The most current approach is to use docker:dind
image, as described here: https://hub.docker.com/_/docker/
最新的方法是使用docker:dind image,如下所述:https://hub.docker.com/_/docker/
Short summary:
简短的摘要:
$ docker run --privileged --name some-docker -d docker:dind
$ docker run --privileged --name some-docker -d docker:dind
and then: $ docker run --rm --link some-docker:docker docker info
然后:$ docker run --rm --link some-docker:docker docker info
#2
3
While in almost all cases I would suggest following @cthulhu's answer and not running "docker in docker", in the cases when you must (e.g. a test suite which tests against multiple docker version), use the following to create additional loopback devices:
虽然在几乎所有情况下我都会建议关注@ cthulhu的答案并且不运行“docker in docker”,在你必须的情况下(例如测试多个docker版本的测试套件),使用以下命令创建其他环回设备:
#!/bin/bash
for i in {0..6}
do
mknod -m0660 /dev/loop$i b 7 $i
done
(Taken from the thread for Docker Issue #7058)
(摘自Docker问题#7058的主题)
#3
2
You can simply run docker inside the docker container using dind
. Try this image from Jerome, as follows:
您可以使用dind在docker容器内运行docker。试试Jerome的这张图片,如下:
docker run --privileged -t -i jpetazzo/dind
docker run --privileged -t -i jpetazzo / dind
Check this page for more details:
https://github.com/jpetazzo/dind
查看此页面了解更多详情:https://github.com/jpetazzo/dind
#1
39
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 in docker'并在docker容器中运行docker?只需挂载docker.sock和docker二进制文件:
docker run -v /var/run/docker.sock:/run/docker.sock -v $(which docker):/bin/docker [your image]
docker run -v /var/run/docker.sock:/run/docker.sock -v $(哪个docker):/ bin / docker [你的形象]
https://github.com/sameersbn/docker-gitlab uses this approach to spin up docker containers, take a look at this image.
https://github.com/sameersbn/docker-gitlab使用这种方法来启动docker容器,看看这个图像。
You can also take a look at: https://registry.hub.docker.com/u/mattgruter/doubledocker/
您还可以查看:https://registry.hub.docker.com/u/mattgruter/doubledocker/
UPDATE on july 2016
2016年7月更新
The most current approach is to use docker:dind
image, as described here: https://hub.docker.com/_/docker/
最新的方法是使用docker:dind image,如下所述:https://hub.docker.com/_/docker/
Short summary:
简短的摘要:
$ docker run --privileged --name some-docker -d docker:dind
$ docker run --privileged --name some-docker -d docker:dind
and then: $ docker run --rm --link some-docker:docker docker info
然后:$ docker run --rm --link some-docker:docker docker info
#2
3
While in almost all cases I would suggest following @cthulhu's answer and not running "docker in docker", in the cases when you must (e.g. a test suite which tests against multiple docker version), use the following to create additional loopback devices:
虽然在几乎所有情况下我都会建议关注@ cthulhu的答案并且不运行“docker in docker”,在你必须的情况下(例如测试多个docker版本的测试套件),使用以下命令创建其他环回设备:
#!/bin/bash
for i in {0..6}
do
mknod -m0660 /dev/loop$i b 7 $i
done
(Taken from the thread for Docker Issue #7058)
(摘自Docker问题#7058的主题)
#3
2
You can simply run docker inside the docker container using dind
. Try this image from Jerome, as follows:
您可以使用dind在docker容器内运行docker。试试Jerome的这张图片,如下:
docker run --privileged -t -i jpetazzo/dind
docker run --privileged -t -i jpetazzo / dind
Check this page for more details:
https://github.com/jpetazzo/dind
查看此页面了解更多详情:https://github.com/jpetazzo/dind