Skip to content

docker-from-docker-compose-networking

Docker-from-docker-compose-networking describes the specific network configuration required to enable communication between a development container and the Docker-in-Docker (DinD) service defined in a docker-compose file. This setup allows the development container to issue Docker commands that are executed by the sibling DinD container, rather than a Docker daemon running on the host or a separate network.

Implementation Context

This pattern is typically utilized in development environments, such as those demonstrated in Docker logging and monitoring stacks^[400-devops__04-CI-CD-Pipelines__devops-cd__monitoring__README.md].

In this arrangement, the service is often explicitly named docker within the docker-compose.yml configuration^[400-devops__04-CI-CD-Pipelines__devops-cd__monitoring__README.md].

Docker Compose Configuration

To establish this connection, the development container must define the docker service (the DinD container) as a specific dependency^[400-devops__04-CI-CD-Pipelines__devops-cd__monitoring__README.md].

  • depends_on: This directive ensures that the docker service is started before the development container initializes^[400-devops__04-CI-CD-Pipelines__devops-cd__monitoring__README.md].
  • network_mode: This directive is crucial as it places the development container inside the network namespace of the docker service^[400-devops__04-CI-CD-Pipelines__devops-cd__monitoring__README.md]. By sharing the network stack, the development container can access the Docker API and control the daemon effectively.

Sources