0

My setup:

  • Computer: Macbook Pro: 13.2.1 (22D68)

  • Laravel Version: 9

  • Docker Version: 4.16.2 (95914)

Problem:

I'm trying to set up a docker-compose configuration to create two testing databases on my Laravel Sail app.

From my research, I've learned to add

'./docker/8.0/create-testing-databases.sql:/docker-entrypoint-initdb.d/create-testing-databases.sh'

to my docker-compose.yml configuration. I don't really understand why it has to be that way. 'create-testing-databases.sh' isn't generated anywhere in my project when I run Docker, so I'm thinking it might be the fact that it doesn't exist that's the issue.

Anyway, I get a "permission-denied" error whenever I tear down and rerun ./vendor/bin/sail up on the script that creates my testing databases.

Section of Terminal Output

admin-20-mysql-1         | 2023-02-21 16:44:17+00:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/create-testing-databases.sh
admin-20-mysql-1         | /usr/local/bin/docker-entrypoint.sh: line 69: /docker-entrypoint-initdb.d/create-testing-databases.sh: Permission denied

Below are my configurations:

./docker/8.0/create-testing-databases.sql: located in root of my project

CREATE DATABASE IF NOT EXISTS `custom_testing_db`;
GRANT ALL PRIVILEGES ON  `custom_testing_db`.* TO 'web'@'%';

CREATE DATABASE IF NOT EXISTS `custom_testing_db2`;
GRANT ALL PRIVILEGES ON  `custom_testing_db2`.* TO 'web'@'%';

docker-compose.yml: located in root of my project

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.1
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.1/app
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${APP_PORT:-80}:80'
            - '${HMR_PORT:-8080}:8080'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
    mysql:
        image: 'mysql'
        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}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
        volumes:
            - 'sail-mysql:/var/lib/mysql'
            - './docker/8.0/create-testing-databases.sql:/docker-entrypoint-initdb.d/create-testing-databases.sh'
        networks:
            - sail
        healthcheck:
            test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
            retries: 3
            timeout: 5s
    redis:
        image: redis:alpine
        container_name: admin-redis
        command: redis-server --appendonly yes
        volumes:
            - ./data/redis:/data
        ports:
            - "8002:6379"
        networks:
            - sail
networks:
    sail:
        driver: bridge
volumes:
    sail-mysql:
        driver: local

What I'm expecting to happen is two testing databases appearing in my "localhost@3306" mysql server:

  • custom_testing_db
  • custom_testing_db2

I've looked at these questions before:

Daniel Haven
  • 156
  • 1
  • 12

1 Answers1

0

The answer is to do this:

- './docker/8.0/create-testing-databases.sql:/docker-entrypoint-initdb.d/create-testing-databases.sql'

Rather than using .sh, use .sql.

Daniel Haven
  • 156
  • 1
  • 12