Docker startup order

Hello,

At container startup, seatable image is often ready before mysql is.

Seatable server in this case won’t ever startup.
So I have to to restart everything few times until the right order is met (which is difficult to monitor when container is launched in background)

wrong order
seatable-redis      | 1:M 10 Apr 2022 07:54:30.610 * Ready to accept connections
seatable-mysql      | 2022-04-10 07:54:30+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
seatable-mysql      | 2022-04-10 07:54:30+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.5.15+maria~focal started.
seatable-mysql      | 2022-04-10 07:54:31+00:00 [Note] [Entrypoint]: MariaDB upgrade not required
seatable            | *** Running /etc/my_init.d/01_init.sh...
seatable            | *** Booting runit daemon...
seatable            | *** Runit started as PID 16
seatable            | *** Running /templates/enterpoint.sh...
seatable            | 2022-04-10 09:54:31 Conf exists
seatable            | 2022-04-10 09:54:31 Nginx ready
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] mysqld (mysqld 10.5.15-MariaDB-1:10.5.15+maria~focal) starting as process 1 ...
seatable            | 2022-04-10 09:54:31 This is a idle script (infinite loop) to keep container running.
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: Uses event mutexes
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: Number of pools: 1
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: Using Linux native AIO
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: Completed initialization of buffer pool
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: 128 rollback segments are active.
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: Creating shared tablespace for temporary tables
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: 10.5.15 started; log sequence number 6856941; transaction id 8406
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] Plugin 'FEEDBACK' is disabled.
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] Server socket created on IP: '::'.
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] Reading of all Master_info entries succeeded
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] Added new Master_info '' to hash table
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] mysqld: ready for connections.
seatable-mysql      | Version: '10.5.15-MariaDB-1:10.5.15+maria~focal'  socket: '/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
seatable-mysql      | 2022-04-10  7:54:31 0 [Note] InnoDB: Buffer pool(s) load completed at 220410  7:54:31
right order
seatable-mysql      | 2022-04-10  7:54:47 0 [Note] InnoDB: Creating shared tablespace for temporary tables
seatable-mysql      | 2022-04-10  7:54:47 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
seatable-mysql      | 2022-04-10  7:54:47 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
seatable-mysql      | 2022-04-10  7:54:47 0 [Note] InnoDB: 10.5.15 started; log sequence number 6856953; transaction id 8406
seatable-mysql      | 2022-04-10  7:54:47 0 [Note] Plugin 'FEEDBACK' is disabled.
seatable-mysql      | 2022-04-10  7:54:47 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
seatable-mysql      | 2022-04-10  7:54:47 0 [Note] Server socket created on IP: '::'.
seatable-mysql      | 2022-04-10  7:54:47 0 [Note] Reading of all Master_info entries succeeded
seatable-mysql      | 2022-04-10  7:54:47 0 [Note] Added new Master_info '' to hash table
seatable-mysql      | 2022-04-10  7:54:47 0 [Note] mysqld: ready for connections.
seatable-mysql      | Version: '10.5.15-MariaDB-1:10.5.15+maria~focal'  socket: '/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
seatable-mysql      | 2022-04-10  7:54:47 0 [Note] InnoDB: Buffer pool(s) load completed at 220410  7:54:47
seatable            | *** Running /etc/my_init.d/01_init.sh...
seatable            | *** Booting runit daemon...
seatable            | *** Runit started as PID 16
seatable            | *** Running /templates/enterpoint.sh...
seatable            | 2022-04-10 09:54:47 Conf exists
seatable            | 2022-04-10 09:54:47 Nginx ready
seatable            | 2022-04-10 09:54:47 This is a idle script (infinite loop) to keep container running.

The perfect solution would be containers manage themself services availability (running manually seatable.sh start whereas docker-compose is especially designed for this is weird to me)

Since the docker-compose.yml is still using version 2 format, I added the deprecated healthcheck directive for controlling startup order.

Here is my custom docker-compose file (including my treafik reverse-proxy setup and its web network), for anyone having the same issue:

version: '2.0'

services:

  db:
    image: mariadb:10.5
    container_name: seatable-mysql
    env_file:
      - .env
    volumes:
      - .docker/database:/var/lib/mysql
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -P 3306 -p${MYSQL_ROOT_PASSWORD?REQUIRED} | grep 'mysqld is alive' || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 30
    networks:
      - seatable-net
    restart: unless-stopped

  memcached:
    image: memcached:1.5.6
    container_name: seatable-memcached
    entrypoint: memcached -m 256
    networks:
      - seatable-net

  redis:
    image: redis:5.0.7
    container_name: seatable-redis
    networks:
      - seatable-net

  seatable:
    image: seatable/seatable-developer:latest
    container_name: seatable
    # ports:
      # - "8089:80"
      # - "443:443"  # If https is enabled, cancel the comment.
    volumes:
      - .docker/datas:/shared  # Requested, specifies the path to Seafile data persistent store.
    env_file:
      - .env
    depends_on:
      db:
        condition: service_healthy
      memcached:
        condition: service_started
      redis:
        condition: service_started
    networks:
      - seatable-net
      - web
    restart: unless-stopped
    labels:
      - "traefik.http.routers.${APP_PROJECT}.entrypoints=http"
      - "traefik.http.routers.${APP_PROJECT}.rule=Host(`${APP_URL}`)"
      - "traefik.http.routers.${APP_PROJECT}.middlewares=redirect-to-https@file"
      - "traefik.http.routers.${APP_PROJECT}-secure.entrypoints=https"
      - "traefik.http.routers.${APP_PROJECT}-secure.rule=Host(`${APP_URL}`)"
      - "traefik.http.routers.${APP_PROJECT}-secure.tls=true"
      - "traefik.http.routers.${APP_PROJECT}-secure.tls.certresolver=letsencrypt"
      - "traefik.http.routers.${APP_PROJECT}-secure.middlewares=redirect-without-www@file"
      - "traefik.http.services.${APP_PROJECT}-service.loadbalancer.server.port=80"

networks:
  seatable-net:
    external: false
  web:
    external:
      name: web