Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose up container start ordering

Now that links are deprecated in docker-compose.yml (and we're able to use the new networking feature to communicate between containers), we've lost a way to explicitly define dependencies between containers. How can we, now, tell our mysql container to come up first, before our api-server container starts up (which connects to mysql via the dns entry myapp_mysql_1 in docker-compose.yml?

like image 683
bloo Avatar asked Oct 18 '22 18:10

bloo


1 Answers

There is a possibility to use "volumes_from" as a workaround until depends_on feature (discussed below) is introduced. Assuming you have a nginx container depending on php container, you could do the following:

nginx:
  image: nginx
  ports:
    - "42080:80"
  volumes:
    - ./config/docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
  volumes_from:
    - php

php:
  build: config/docker/php
  ports:
    - "42022:22"
  volumes:
    - .:/var/www/html
  env_file: config/docker/php/.env.development

mongo:
  image: mongo
  ports:
    - "42017:27017"
  volumes:
    - /var/mongodata/wa-api:/data/db
  command: --smallfiles

One big caveat in the above approach is that the volumes of php are exposed to nginx, which is not desired. But at the moment this is one docker specific workaround that could be used.

depends_on feature This probably would be a futuristic answer. Because the functionality is not yet implemented in Docker (as of 1.9)

There is a proposal to introduce "depends_on" in the new networking feature introduced by Docker. But there is a long running debate about the same @ https://github.com/docker/compose/issues/374 Hence, once it is implemented, the feature depends_on could be used to order the container start-up, but at the moment, you would have to resort to the above approach.

like image 181
Phani Avatar answered Oct 30 '22 18:10

Phani