0

Using Linux Mint. I have the following docker-compose.yml. When I run docker-compose up -d it's very common that all the containers except for my web container start up, and if I run the command several more times, eventually my web container is up. There is nothing in the docker logs and no error is thrown. I'm at my wits end as to why this happens. Can someone shed some light on what else I could do in order to figure this out?

Using the same file, this also happens on Ubuntu20.04, but it is much less frequent.

version: '3'

services:
  db:
    container_name: db_container
    image: mysql:5.6
    volumes:
      - dbBackup.sql:/docker-entrypoint-initdb.d/backup.sql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: blah
      MYSQL_DATABASE: dbname
      MYSQL_USER: myUser
      MYSQL_PASSWORD: myPassword
    ports:
      - 3306:3306
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci

  web:
    container_name: web_container
    build: ./web # This is just a centos image with a few things like httpd installed.
    volumes:
      - ./some_dir:codebase
      - ./config:codebase/config
    links:
      - redis
    depends_on:
      - db

  redis:
    container_name: redis
    image: redis

  mailhog:
    container_name: mailhog
    image: mailhog/mailhog
    ports:
      - 1025:1025
      - 8025:8025

Dockerfile for web container:

FROM centos/centos8

RUN dnf -y update && \
    dnf -y install epel-release httpd httpd-tools {more stuff}

EXPOSE 80 443

COPY docker-entrypoint.sh /usr/local/bin/

ENTRYPOINT [ "docker-entrypoint.sh" ]

docker-entrypoint.sh:

#!/bin/bash
/usr/sbin/httpd -D FOREGROUND
Hiro
  • 43
  • 5
  • what process is configured to be running within web container? in other words can you show your dockerfile for `web`? – Alexey R. Feb 24 '22 at 12:40
  • What you're describing sounds like the symptom where the `web` container starts up before the `db` container is fully ready; it often can take a database 30-60 seconds to be ready to accept results. `depends_on:` on its own isn't enough. If you run `docker-compose up` without the `-d` option, do you see database startup messages after the application fails? Also see [Docker Compose wait for container X before starting Y](https://stackoverflow.com/questions/31746182/docker-compose-wait-for-container-x-before-starting-y). – David Maze Feb 24 '22 at 14:32
  • @DavidMaze I tried this and there's no meaningful messages when using `docker-compose up` I tried amending the web container depends on to this: `depends_on: db: condition: service_completed_successfully` But this just results in the web container never starting. With or without the -d, it just hangs. – Hiro Feb 25 '22 at 13:40
  • @AlexeyR. I have added my dockerfile and the docker-entrypoint.sh to the question – Hiro Feb 25 '22 at 13:45

0 Answers0