I'm very new to laravel and docker and trying to connect mysql to php container(laravel). I thought set right my docker-compose.yml and env file in laravel project.
Also, I can connect to mysql db inside the container.
Here is a error when I did php artisan migrate :
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = myapp and table_name = migrations and table_type = 'BASE TABLE')
Can anyone know what happened?
docker-compose.yml
version: '3'
services:
php:
container_name: php
build: ./docker/php
volumes:
- ./myapp/:/var/www
nginx:
image: nginx:latest
container_name: nginx
ports:
- 80:80
volumes:
- ./myapp/:/var/www
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
db:
image: mysql:8.0
container_name: db
environment:
MYSQL_ROOT_PASSWORD: root1234
MYSQL_DATABASE: myapp
MYSQL_USER: docker
MYSQL_PASSWORD: docker
TZ: 'Asia/Tokyo'
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
ports:
- 3306:3306
env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myapp
DB_USERNAME=docker
DB_PASSWORD=docker