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: host
to 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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…