在 docker 容器中运行 docker?

编程入门 行业动态 更新时间:2024-10-11 09:26:58
本文介绍了在 docker 容器中运行 docker?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 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 [你的镜像]

github/sameersbn/docker-gitlab 使用这种方法来启动 docker 容器,采取看看这张图片.

github/sameersbn/docker-gitlab uses this approach to spin up docker containers, take a look at this image.

你也可以看看:registry.hub.docker/u/mattgruter/doubledocker/

2016 年 7 月更新

最新的方法是使用 docker:dind 图像,如下所述:hub.docker/_/docker/

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

简短的总结:

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

然后:$ docker run --rm --link some-docker:docker docker info

更多推荐

在 docker 容器中运行 docker?

本文发布于:2023-10-29 00:22:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538187.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!