Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control docker-compose build order?

I have three services to build, A、B and C. A should be built in the very first place, because B and C depend on A (they import A as image). I thought they should be built in order but I just find out they are built in some random order?

So, how do I control build order in docker-compose.yml?

like image 302
Kim Avatar asked Sep 19 '17 08:09

Kim


People also ask

Does docker compose run in order?

Compose always starts and stops containers in dependency order, where dependencies are determined by depends_on , links , volumes_from , and network_mode: "service:..." .

What is Depends_on in docker compose?

depends_on is a Docker Compose keyword to set the order in which services must start and stop. For example, suppose we want our web application, which we'll build as a web-app image, to start after our Postgres container.

What is docker compose build and up?

Description. Builds, (re)creates, starts, and attaches to containers for a service. Unless they are already running, this command also starts any linked services. The docker compose up command aggregates the output of each container (like docker compose logs --follow does).


1 Answers

Update: In recent practice, I have found my answer to only pertain to run ordering.
Refer to the answer by Quinten Scheppermans and the comment by Authur Weborg about dobi.

You can control build order using depends_on directive.

services:   ...    B:     depends_on:       - A   C:     depends_on:       - A 
like image 100
Oluwafemi Sule Avatar answered Sep 21 '22 22:09

Oluwafemi Sule