如何在 openshift 上从 docker 容器内启动新的 docker 容器

How to launch a new docker container from inside a docker container on openshift

用例:

我想编写一个服务器应用程序,为每个客户启动一个 docker 容器,其中仅包含特定的客户数据(用于数据保护)。该服务应 运行 在 openshift 或 openshift 源上。

我搜索过的地方:

openshift origin latest documentation

openshift origin m4 documentation

我已经知道的:

如果第一个容器是特权容器或 docker 套接字,我可以从 docker 容器内部启动一个 docker 容器,并且主机中的二进制文件已链接到其中。

[编辑 2015 年 10 月 31 日] 赞:docker run -v /var/run/docker.sock:/var/run/docker.sock ...

我不知道的:

是否可以在 openshift 上启动特权 docker 容器或使用 docker 容器内部的 openshift api 启动另一个 docker 容器(使用具体运行时间配置)?顺便说一句:"mother" 容器应该是可扩展的。

阅读“~jpetazzo/Using Docker-in-Docker for your CI or testing environment? Think twice.”后,我会考虑使用同级容器而不是嵌套容器。
以下摘录涉及 CI 但可以应用于每个客户端的 openshift 启动容器(而不是 CI 启动容器)

Do you really want Docker-in-Docker? Or do you just want to be able to run Docker (specifically: build, run, sometimes push containers and images) from your CI system, while this CI system itself is in a container?

The simplest way is to just expose the Docker socket to your CI container, by bind-mounting it with the -v flag.

Simply put, when you start your CI container (Jenkins or other), instead of hacking something together with Docker-in-Docker, start it with:

docker run -v /var/run/docker.sock:/var/run/docker.sock ...

Now this container will have access to the Docker socket, and will therefore be able to start containers. Except that instead of starting "child" containers, it will start "sibling" containers.

有可能 - OpenShift 对 运行 执行 Docker 和源构建的构建容器做同样的事情。在容器安全上下文中(在您的 pod 定义中)将 priviliged 设置为 true 并定义 /var/run/docker.sock 的卷挂载。

请注意,您需要有权启动特权容器(不允许普通用户设置 priv 或主机挂载),这可以通过将您的项目添加到 "priviliged" 安全性来完成上下文约束(https://docs.openshift.org/latest/admin_guide/manage_scc.html)。在 1.0.7 中有一个策略命令可以使它更容易 oc policy add-scc-to-service-account