Organizing docker launch container

Now that link deprecated in docker-compose.yml (and we can use the new network function to communicate between containers), we have lost the way to explicitly define dependencies between containers. How can we now tell our mysql container to appear first before our api-server container starts (which connects to mysql via the dns entry myapp_mysql_1 in docker-compose.yml ?

+5
source share
1 answer

It is possible to use "volume_from" as a workaround until the depend_on function is introduced (discussed below). Assuming you have a nginx container depending on the php container, you can 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 php volumes undergo nginx, which is undesirable. But at the moment this is one docker that can be used.

function depend_on . Perhaps this will be a futuristic answer. Since the functionality has not yet been implemented in Docker (since 1.9)

There is a suggestion to introduce "depend_on" in the new network function introduced by Docker. But there is a long discussion about the same @ https://github.com/docker/compose/issues/374 Therefore, as soon as a function is implemented that can be used to order container launch, but at the moment you have to resort to the above approach.

+3
source

Source: https://habr.com/ru/post/1240050/


All Articles