Repository: miniflux/v2 (language: go)

Issue:
Why is it suggested to start the database first and then the application in Docker Compose?
[Link to the documentation](https://miniflux.app/docs/installation.html#docker:~:text=Start%20the%20database%20first%20docker%2Dcompose%20up%20%2Dd%20db%20and%20then%20the%20application%20docker%2Dcompose%20up%20miniflux.)

It is said:
> Start the database first `docker-compose up -d db` and then the application `docker-compose up miniflux`.

Isn't `depends_on` enough to manage the order of the containers to start? What is the reason for this suggestion?


Discussion / hints:
The `depends_on` instruction expresses dependency between services, but Docker doesn't  wait until the database is ready to accept connections.

Miniflux is faster to start than Postgresql, and it will fail to connect to the database until Postresql is fully ready.

You can find more information on Docker's website: https://docs.docker.com/compose/compose-file/compose-file-v3/#depends_on

Makes sense. Though, I was researching the docker compose features and found `depends_on.condition.service_healthy` in the [latest compose spec](https://docs.docker.com/compose/compose-file/#long-syntax-1).

And it worked for me in Docker Desktop 4.16.3 on Windows. Miniflux container is waiting for the DB container to become healthy.

Here is a compose file:

```yaml
services:
  miniflux:
    image: miniflux/miniflux:latest
    ports:
      - "80:8080"
    depends_on:
      db:
        condition: service_healthy # <-----------
    environment:
      - DATABASE_URL=postgres://miniflux:secret@db/miniflux?sslmode=disable
      - RUN_MIGRATIONS=1
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "/usr/bin/miniflux", "-healthcheck", "auto"]
  db:
    image: postgres:15
    environment:
      - POSTGRES_USER=miniflux
      - POSTGRES_PASSWORD=secret
    volumes:
      - miniflux-db:/var/lib/postgresql/data
    restart: unless-stopped
    healthcheck: # <-----------
      test: ["CMD", "pg_isready", "-U", "miniflux"]
      interval: 10s
      start_period: 30s
volumes:
  miniflux-db:
```

I can try sending a PR for changing the docs if you like, as a gratitude for the software.
> I can try sending a PR for changing the docs if you like, as a gratitude for the software.

Sure. Contributions are welcome. 

I did not know that `depends_on.condition.service_healthy` is now available.
Investigating the code I've found two relevant changes:

- in Feb 2021 [on the website](https://github.com/miniflux/website/commit/fa1ea20dede1568ce91c497fc0c4911445bdeb8e) and [in the contrib](https://github.com/miniflux/v2/pull/1041) that adds the `depends_on.condition` — the same what I am going to do now.
- in Oct 2021 [on the website](https://github.com/miniflux/website/commit/203c5ee9841269035985233a858ebea433ccab34) and [in the contrib](https://github.com/miniflux/v2/pull/1270) that removes it.

From the latter PR it becomes clear that this `condition` was removed for compatibility with compose file v3 format.

Looking closer into the compose documentation I've found out that this option was present in [v2](https://docs.docker.com/compose/compose-file/compose-file-v2/#depends_on) but was removed from [v3](https://docs.docker.com/compose/compose-file/compose-file-v3/#depends_on).

However, it was added again in the latest Compose file format which has no version number anymore:

> The latest and recommended version of the Compose file format is defined by the [Compose Specification](https://github.com/compose-spec/compose-spec/blob/master/spec.md). This format merges the 2.x and 3.x versions and is implemented by Compose 1.27.0+.
>
> -- <cite>https://docs.docker.com/compose/compose-file/compose-versioning/#versioning</cite>

That being said, I think it's worth updating the examples to the latest Compose file format.

Originally I was going to ask here why the health check condition was added and then removed, but in the course of writing the comment I've figured it out (seemingly).

Fix patch:
diff --git a/contrib/docker-compose/README.md b/contrib/docker-compose/README.md
index 300d381e94c..f2200d99647 100644
--- a/contrib/docker-compose/README.md
+++ b/contrib/docker-compose/README.md
@@ -8,6 +8,5 @@ Here are few Docker Compose examples:
 - `traefik.yml`: Use Traefik as reverse-proxy with automatic HTTPS
 
 ```bash
-docker-compose -f basic.yml up -d db
-docker-compose -f basic.yml up
+docker compose -f basic.yml up -d
 ```
diff --git a/contrib/docker-compose/basic.yml b/contrib/docker-compose/basic.yml
index b02e4d5bc15..ebb5eb6e894 100644
--- a/contrib/docker-compose/basic.yml
+++ b/contrib/docker-compose/basic.yml
@@ -1,4 +1,3 @@
-version: '3.4'
 services:
   miniflux:
     image: ${MINIFLUX_IMAGE:-miniflux/miniflux:latest}
@@ -7,7 +6,8 @@ services:
     ports:
       - "80:8080"
     depends_on:
-      - db
+      db:
+        condition: service_healthy
     environment:
       - DATABASE_URL=postgres://miniflux:secret@db/miniflux?sslmode=disable
       - RUN_MIGRATIONS=1
diff --git a/contrib/docker-compose/caddy.yml b/contrib/docker-compose/caddy.yml
index acaea5a9521..6347fbf2bdf 100644
--- a/contrib/docker-compose/caddy.yml
+++ b/contrib/docker-compose/caddy.yml
@@ -1,4 +1,3 @@
-version: '3.4'
 services:
   caddy:
     image: caddy:2
@@ -16,7 +15,8 @@ services:
     image: ${MINIFLUX_IMAGE:-miniflux/miniflux:latest}
     container_name: miniflux
     depends_on:
-      - db
+      db:
+        condition: service_healthy
     environment:
       - DATABASE_URL=postgres://miniflux:secret@db/miniflux?sslmode=disable
       - RUN_MIGRATIONS=1
diff --git a/contrib/docker-compose/traefik.yml b/contrib/docker-compose/traefik.yml
index eafa7cd7700..7cb95b0e47f 100644
--- a/contrib/docker-compose/traefik.yml
+++ b/contrib/docker-compose/traefik.yml
@@ -1,4 +1,3 @@
-version: '3.4'
 services:
   traefik:
     image: "traefik:v2.3"
@@ -21,7 +20,8 @@ services:
     image: ${MINIFLUX_IMAGE:-miniflux/miniflux:latest}
     container_name: miniflux
     depends_on:
-      - db
+      db:
+        condition: service_healthy
     expose:
       - "8080"
     environment:


Test patch: