How to control docker-compose build order?

≯℡__Kan透↙ 提交于 2020-01-01 04:01:27

问题


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?


回答1:


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



回答2:


The accepted answer above does not seem correct.

As seen in the documentation

There are several things to be aware of when using depends_on:

depends_on does not wait for db and redis to be “ready” before starting web - only until they have been started. If you need to wait for a service to be ready, see Controlling startup order for more on this problem and strategies for solving it.

Version 3 no longer supports the condition form of depends_on.

The depends_on option is ignored when deploying a stack in swarm mode with a version 3 Compose file.



来源:https://stackoverflow.com/questions/46295806/how-to-control-docker-compose-build-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!