Cvetan's avatar

Changin Mysql configuration in Laravel Sail makes it non-functional(mysql container wont start)

I've changed sail configuration a bit, removing unneded services, and just for practice purposes I added root password and remove flag to allow empty password and now no matter what I do, I can't start mysql container.

docker-compose

services:
    acme-core.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.3
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.3/app
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${APP_PORT:-80}:80'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
            IGNITION_LOCAL_SITES_PATH: '${PWD}'
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
            - mailpit
    mysql:
        image: 'mysql/mysql-server:8.0'
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ROOT_HOST: '%'
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
        volumes:
            - 'sail-mysql:/var/lib/mysql'
            - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
        networks:
            - sail
        healthcheck:
            test:
                - CMD
                - mysqladmin
                - ping
                - '-p${DB_PASSWORD}'
            retries: 3
            timeout: 5s
    mailpit:
        image: 'axllent/mailpit:latest'
        ports:
            - '${FORWARD_MAILPIT_PORT:-1025}:1025'
            - '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025'
        networks:
            - sail
networks:
    sail:
        driver: bridge
volumes:
    sail-mysql:
        driver: local

.env

APP_NAME="ACME Core CMS"
APP_SERVICE=acme-core.test
APP_ENV=local
APP_KEY=base64:uMUP0PMT6gsz4K/Cx0YGwVM3CtuH+3khwoEtY25xe0E=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US

APP_MAINTENANCE_DRIVER=file
APP_MAINTENANCE_STORE=database

BCRYPT_ROUNDS=12

LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=acme-core
DB_USERNAME=root
DB_PASSWORD=root

SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null

BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database

CACHE_STORE=database
CACHE_PREFIX=

MAIL_MAILER=log
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

Any ideas why this happens? I've tride deleting volumes, all images, redownloading, rebuilding image, nothing works.

0 likes
2 replies
LaryAI's avatar
Level 58

It seems like the issue might be related to the MySQL container configuration in your docker-compose.yml file. Here are a few things you can check and try to resolve the issue:

  1. Environment Variables Consistency: Ensure that the environment variables used in the docker-compose.yml file match those in your .env file, especially for MySQL credentials.

  2. MySQL Root Password: Since you've added a root password, make sure that the password does not contain characters that might need to be escaped in the Docker environment. Also, verify that the password is correctly set in both the .env file and the docker-compose.yml file.

  3. Volume Persistence: You mentioned that you tried deleting volumes, but ensure that the MySQL volume is completely removed so that any incorrect configurations are not persisted. You can remove the volume using the following Docker command:

    docker volume rm sail-mysql
    
  4. Health Check Configuration: The health check configuration in your docker-compose.yml might be causing issues if the password is not correctly recognized. You can temporarily remove the health check to see if that allows the MySQL container to start.

  5. Docker Logs: Check the logs of the MySQL container to see if there are any error messages that can give you more insight into what might be going wrong. Use the following command to get the logs:

    docker logs <mysql-container-id>
    
  6. Simplify Configuration: As a test, simplify your MySQL service configuration to the bare minimum needed to run and gradually add configurations to identify the problematic setting.

Here is a simplified version of your MySQL service configuration for testing:

mysql:
    image: 'mysql/mysql-server:8.0'
    ports:
        - '${FORWARD_DB_PORT:-3306}:3306'
    environment:
        MYSQL_ROOT_PASSWORD: 'root'  # Ensure this matches your .env DB_PASSWORD
        MYSQL_DATABASE: 'acme-core'
    volumes:
        - 'sail-mysql:/var/lib/mysql'
    networks:
        - sail

Make sure to replace 'root' with the actual password you want to use, matching the DB_PASSWORD in your .env file.

After making these changes, try running your Docker containers again. If the MySQL container still fails to start, the logs should provide more specific details on the issue.

Please or to participate in this conversation.