0

I've to write docker compose for importing mysql file of size 1.5gb inside container. Also my backend should wait for the mysql import to complete also next build it should not import data my docker-compose file

  mysql:
    image: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 12345@root
      MYSQL_DATABASE: dockerDB
    volumes:
      - ./mysql_data:/var/lib/mysql
      - ./init.sql:/docker-entrypoint-initdb.d/datadump.sql
    healthcheck:
      test:
        [
          "CMD",
          "mysqladmin",
          "ping",
          "-uroot",
          "-p12345@root"
        ]
    networks:
      - local_net

  backend:
    build: ./Backend/
    image: rails_backend
    container_name: backend
    restart: always
    ports:
      - 3000:3000
    depends_on:
      mysql:
        condition: service_healthy
    networks:
      - local_net
    env_file:
      - ./Backend/.env
    command: /root/.rbenv/shims/rails s -p 3000 -b '0.0.0.0'

i have tried health check using healthcheck: test: [ "CMD", "mysqladmin", "ping", "-uroot", "-p12345@root" ] but when i hit backend it crash as mysql has not imported all data

  • 1
    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). I might change the database `healthcheck:` to force a TCP connection; as it's currently written I think the `mysqladmin ping` can succeed during the first stage when the database is up but only running the init scripts, and not externally accessible. – David Maze May 30 '23 at 09:31

0 Answers0