# What is the difference between links and depends_on in docker_compose.yml?

Both **`links`** and **`depends_on`** are used in a Docker Compose file (**`docker-compose.yml`**) to define relationships between containers. However, they differ in the way they establish these relationships.

## Links

**`links`** is used to link a container to another container in the same Compose file. It creates a network connection between the linked containers, allowing them to communicate with each other. For example, if you have a web application container that depends on a database container, you can use **`links`** to ensure that the web application can access the database.

Here's an example of using **`links`** in a Compose file:

```yaml
version: '3'

services:
  web:
    build: .
    links:
      - db
  db:
    image: postgres
```

In this example, the **`web`** service links to the **`db`** service, allowing it to connect to the Postgres database.

# depends_on

**`depends_on`**, on the other hand, is used to define the order in which services are started. It does not create a network connection between the services, but rather ensures that one service starts before another. For example, if you have a web application container that depends on a database container, you can use **`depends_on`** to ensure that the database is started before the web application.

Here's an example of using **`depends_on`** in a Compose file:

```yaml
version: '3'

services:
  web:
    build: .
    depends_on:
      - db
  db:
    image: postgres
```

In this example, the **`web`** service depends on the **`db`** service, ensuring that the database is started before the web application.

## Summary

In summary, **`links`** is used to link containers and enable communication between them, while **`depends_on`** is used to define the order in which services are started.