Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
586 views
in Technique[技术] by (71.8m points)

centos - Run docker inside a docker container?

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.

The problem is that I can't actually start docker on my container. If I try

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.

A bit more information

Host machine is running fedora 20 (will eventually be running amazon linux on an ec2)

Docker container is running centos 7.0

Host is running Docker version 1.2.0, build fa7b24f/1.2.0

Container is running docker-0.11.1-22.el7.centos.x86_64

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 uses this approach to spin up docker containers, take a look at this image.

You can also take a look at: https://registry.hub.docker.com/u/mattgruter/doubledocker/

UPDATE on july 2016

The most current approach is to use docker:dind image, as described here: https://hub.docker.com/_/docker/

Short summary:

$ docker run --privileged --name some-docker -d docker:dind

and then: $ docker run --rm --link some-docker:docker docker info


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...