docker-compose中的docker-compose:共享网络 [英] docker-compose in docker-compose: Share network
问题描述
我知道通过将以下卷添加到docker-compose来共享docker套接字: /var/run/docker.sock:/var/run/docker.sock
使用的文件为您的CI或测试环境使用Docker-in-Docker?
I am aware of sharing the docker socket by adding this volume /var/run/docker.sock:/var/run/docker.sock
to the docker-compose file as proposed by Using Docker-in-Docker for your CI or testing environment?
我创建了这个简单的示例/实验设置,以便可以在Windows中启动docker-compose
I created this simple example/experiment setup to make it possible to start docker-compose in a docker-compose container, without sharing everything.
docker-compose.yml
services:
manager:
build:
context: ./manager
privileged: true
ngnix:
image: nginx:latest
经理/ Dockerfile
FROM nginx:latest
RUN apt-get -y update \
&& apt-get install -y iputils-ping docker-compose
RUN mkdir /app
WORKDIR /app
COPY . ./
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["ping", "www.google.com"]
经理/entrypoint.sh
#!/bin/sh
set -e
service docker start
exec "$@"
经理/docker-compose.yml
services:
foobar:
image: ruby:latest
现在可能的命令是: docker-compose up -d; docker-compose exec manager docker-compose run foobar / bin / bash
目前,我没有共享docker-compose网络在主机和管理器之间。当然,这就是docker在每个设计中的工作方式。因此,在执行上述命令后,从 foobar
容器执行 ping ngnix
将不起作用。
For now, I did not manage to share the docker-compose network between the host and the one on the manager. This, off course, is how docker is intended to work per design. Therefore after executing the command above executing ping ngnix
from the foobar
container will not work.
我的问题是: 我该如何进行这项工作?
My question is: how can I make this work?
我尝试过以不同的方式将 network:host
添加到manager / docker-compose.yml,但这没有用,或者我太愚蠢,无法正确执行。
I tried adding network: host
to the manager/docker-compose.yml in different ways but that did not work, or I was too stupid to do it correct.
推荐答案
正如David Maze指出的那样,唯一的解决方案就是共享套接字。有关此内容的更多阅读信息:
As David Maze points out possibly the only solution is to share the socket. More reading information on that here:
- Using Docker-in-Docker for your CI or testing environment?
- Docker in Docker?
这篇关于docker-compose中的docker-compose:共享网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!