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
?
You can control build order using
depends_on
directive.As stated in https://github.com/docker/compose/blob/e9220f45df07c1f884d5d496507778d2cd4a1687/compose/project.py#L182-L183
So for me it worked by manually sorting the services with the depending services at first and following the services which is used by the other and the other as last.
Example
Source: https://github.com/docker/compose/issues/5228#issuecomment-565469948
The accepted answer above does not seem correct.
As seen in the documentation