如何在Docker(DIND)内运行Docker容器? [英] How to run docker container inside docker (DIND)?

查看:130
本文介绍了如何在Docker(DIND)内运行Docker容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在docker https://hub.docker>中使用Docker在另一个容器中运行一个容器.com/_/docker .

I am trying to run a container inside another container using Docker inside docker https://hub.docker.com/_/docker.

当我运行以下命令时:

docker run --privileged docker:stable-dind docker run hello-world

我收到以下错误消息:

docker:无法通过unix:///var/run/docker.sock连接到Docker守护程序.泊坞窗守护程序正在运行吗?请参阅"docker run --help".

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?. See 'docker run --help'.

我必须缺少某些东西,如何在docker内部运行docker?

I must be missing something, how can I run docker inside docker?

推荐答案

我认为您不能一口气做到这一点(其他人可能会纠正我).但是,如 hub.docker.com/_/docker/所述,您可以开始将docker-in-docker容器作为后台守护程序( -d ),然后在其中启动其他容器.

I don't think you can do this in a one-liner (others might correct me). However, as explained at hub.docker.com/_/docker/, you can start the a docker-in-docker container as a background daemon (-d) and then start other containers inside.

要启动父容器,请运行

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

名称 some-docker 是任意的.稍后将用于标识此容器.要在其中启动容器,请运行

The name some-docker is arbitrary. It will be used to identify this container later on. To start a container inside, run

docker run  --link some-docker:docker docker run hello-world

-link 选项公开父容器的网络端口并设置环境变量,以便内部容器使用dind映像中的docker.

The --link option exposes the network ports of the parent container and sets environment variables, such that the inner container uses docker from the dind image.

这篇关于如何在Docker(DIND)内运行Docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆