How to connect docker containers in separate deployments on the same machine using docker-compose?

I find it difficult to determine how to connect containers that belong to different projects running on the docker, running on the same host.

Let's say I have a set of containers in Deployment A :

root@debussy :~# docker ps | awk '{print $2}' | grep "cl" cl-worker:latest cl-nginx:latest cl-app:latest cl-rabbitmq:latest cl-memcached:latest cl-db:latest 

All of these containers are launched from a separate deployment-a.yml configuration file. Now we also have another Deployment B , with its own `deployment-b.yml:

 root@debussy :~# docker ps | awk '{print $2}' | grep "stockagents" stockagents-app:latest 

Is it possible to access the database ( cl-db container) from stockagents-app using a specific configuration in deployment-b.yml and / or deployment-a.yml ?

NOTE. . I know how to do this using the pure docker and linking containers using --link , but is there a way to achieve the same behavior using only docker-compose and its configuration files?

+5
source share
2 answers

It seems that the latest versions of docker-compose (at least 1.5.2) support the "external_links" option in the docker-compose.yml which allows you to specify containers running outside the current configuration.

This is exactly the function I was looking for when trying to share common services (like MySQL) between containers in separate deployments.

+2
source

It looks like your requirements are outgrowing the possibilities of creating dockers. You need to tinker with an orchestration instrument (more or less complicated). We also use Ubuntu and for our environment SkyDNS + SkyDock seems to be a good and simple solution (of course, no etcd ). Deployment involves three steps: you just need to pull out the images, reconfigure the SkyDock daemon, and launch SkyDNS and SkyDock . If you are familiar with Russian, you can find a good deployment guide here .

The main advantage of this solution is the new DNS zone available inside the Docker environment. Containers can call each other by name. But since reverse lookup is missing in SkyDNS , you need to explicitly pass the hostnames:

  web: image: django hostname: web.django.dev.skydns.local build: ./webapp ports: - "8000:8000" environment: - DEBUG=true - SEND_EMAILS=false 

Thus, your container will be accessible by the name web.django.dev.skydns.local from any container.

0
source

All Articles