skip to Main Content

Trying to get away from using Sail, and want to make my application without Sail. So far I can’t get mysql server to start running. I’ve tried changing the env DB_HOST to the name of the db in the docker-compose, and it looks like the server is running when I do docker compose up --build, however when after, when I do php artisan migrate:fresh --seed nothing seems to be working. Any help would be appreciated!

My docker-compose:

version: "3.8"

services:
  laravel-vue-app:
    build: .
    ports:
        - "8080:8080"
    depends_on:
        - mysql
    volumes:
        - .:/var/www/html
        - /var/www/html/node_modules
        - /var/www/html/vendor
    networks:
        - app-network
mysql:
    image: "mysql/mysql-server:8.0"
    container_name: database
    ports:
        - "${FORWARD_DB_PORT:-3306}:3306"
    environment:
        MYSQL_ROOT_PASSWORD: "${DB_PASSWORD}"
        MYSQL_DATABASE: "${DB_DATABASE}"
        MYSQL_USER: "${DB_USERNAME}"
        MYSQL_PASSWORD: "${DB_PASSWORD}"
        MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
volumes:
        - mysql-data:/var/lib/mysql
networks:
        - app-network

and my ENV:

DB_CONNECTION=mysql
DB_HOST=database
DB_PORT=3306

And the error I get after I do docker-compose up –build, in a new terminal when running php artisan migrate:fresh –seed

SQLSTATE[HY000] [2002] php_network_getaddresses: 
getaddrinfo for database failed: nodename nor servname provided, or not known (Connection: mysql, SQL: select table_name as `name`, 
(data_length + index_length) as `size`, table_comment as `comment`, 
engine as `engine`, table_collation as `collation` from 
information_schema.tables where table_schema = 'bigapp' and table_type
in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)

2

Answers


  1. You must pass mysql container ip address for DB_HOST not container name or database must point to mysql containers network address.

    Login or Signup to reply.
  2. You need to pass the database service name in DB_HOST which according to docker-compose.yml file is ‘mysql’. So setting

    DB_HOST=mysql
    

    should solve the problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search