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
405 views
in Technique[技术] by (71.8m points)

docker-compose in docker-compose: Share network

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?

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

manager/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"]

manager/entrypoint.sh

#!/bin/sh

set -e
service docker start
exec "$@"

manager/docker-compose.yml

services:
  foobar:
    image: ruby:latest

Possible command now would be: docker-compose up -d; docker-compose exec manager docker-compose run foobar /bin/bash

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?

I tried adding network: hostto the manager/docker-compose.yml in different ways but that did not work, or I was too stupid to do it correct.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

As David Maze points out possibly the only solution is to share the socket. More reading information on that here:


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

...