# depends\_on

用来表示服务之间的依赖关系。服务的依赖关系会导致下面的行为：

* docker-compose up会按照依赖顺序启动服务。下面的示例中，db和redis都在web之前启动。
* docker-compose up SERVICE自动包含SERVICE的依赖。在下面示例，docker-compose up web也会创建和启动db和redis。
* docker-compose stop按照依赖顺序停止服务。下面的示例中，web在db和redis之前被停止。

```
 version: "3.8"
 services:
   web:
     build: .
     depends_on:
       - db
       - redis
   redis:
     image: redis
   db:
     image: postgres
```

Note:

* depends\_on在启动web之前，不会等待db和redis进入ready状态。只会等待它们被启动。如果需要等待一个服务进入ready状态。参考[控制启动顺序](https://docs.docker.com/compose/startup-order/)来解决这个问题。
* 版本3不再支持depends\_on的condition形式。
* 当通过版本3的Compose文件在swarm节点上部署一个stack时，depends\_on选项会被忽视。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://camelgemonion.gitbook.io/docker/dockercompose.yaml-wen-jian-zhong-chang-yong-zhi-ling/untitled-12/untitled-3.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
