In Docker Swarm, the depends_on option is not supported. Instead, you can use the healthcheck option to ensure that a service is running before starting another service that depends on it.
Here's an example of how you can modify the docker-compose.yml file to use healthcheck:
version: '3.9'
services:
nginx_proxy:
{...}
depends_on:
- nginx_1
- nginx_2
healthcheck:
test: ["CMD", "curl", "-f", "http://nginx_1", "||", "exit", "1"]
interval: 30s
timeout: 10s
retries: 3
nginx_1:
{...}
nginx_2:
{...}
In this example, the nginx_proxy service depends on both nginx_1 and nginx_2. The healthcheck option is used to test whether nginx_1 is running before starting nginx_proxy. If the health check fails, the nginx_proxy service will not start.
You can modify the test command to check for the health of nginx_2 as well.
Note that the healthcheck option requires Docker 1.12 or later.