FG
☁️ Cloud & DevOpsDocker

Is there a way to delay container startup to support dependant services with a longer startup time

Freshabout 19 hours ago
Mar 14, 20260 views
Confidence Score95%
95%

Problem

I have a MySQL container that takes a little time to start up as it needs to import data. I have an Alfresco container that depends upon the MySQL container. At the moment, when I use fig, the Alfresco service inside the Alfresco container fails when it attempts to connect to the MySQL container... ostensibly because the MySQL service is not yet listening. Is there a way to handle this kind of issue in Fig?

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Implement Wait-for-it Script for MySQL Dependency

Medium Risk

The Alfresco container attempts to connect to the MySQL container before it is fully initialized and ready to accept connections. This leads to connection failures as the MySQL service is not yet listening on the expected port.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Add Wait-for-it Script to Alfresco Container

    Download the 'wait-for-it' script, which will pause the startup of the Alfresco service until the MySQL service is ready.

    bash
    curl -o wait-for-it.sh https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh && chmod +x wait-for-it.sh
  2. 2

    Modify Dockerfile for Alfresco

    Update the Dockerfile for the Alfresco container to include the 'wait-for-it' script, ensuring it is available at runtime.

    dockerfile
    COPY wait-for-it.sh /usr/local/bin/wait-for-it
  3. 3

    Update Alfresco Service Command

    Modify the command that starts the Alfresco service in the docker-compose.yml file to use the 'wait-for-it' script, specifying the MySQL service and port.

    yaml
    command: ["/usr/local/bin/wait-for-it", "mysql:3306", "--", "alfresco-start-command"]
  4. 4

    Test the Configuration

    Build and run the updated containers to ensure that the Alfresco container waits for MySQL to be ready before starting.

    bash
    docker-compose up --build

Validation

Check the logs of the Alfresco container to confirm that it waits for the MySQL service to be ready before attempting to connect. You should see a message indicating that it is waiting for MySQL before starting the Alfresco service.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

dockerdocker-composecontainers