I recommend to use Laravel Sail instead of creating a Docker file yourself.
Aug 13, 2022
7
Level 3
Trouble connecting to Mysql in docker within a Laravel 9 project
I just recently migrated my Lumen API to Laravel 9. I also decided to use docker instead of homestead. I've not been able to successfully connect to the mysql instance running in the container. I keep getting access denied even when I explicitly turned off mysql password (Set it to false). Could this be a specific Laravel 9 issue because even when I ssh into the mysql container and try to access mysql I get the same access denied error
my env vars
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=test_db
DB_USERNAME=root
DB_PASSWORD=pass
my docker-compose
version: "3.7"
services:
app:
build: .
container_name: cookbookshq
depends_on:
- db
volumes:
- ./:/var/www
networks:
- cookbooks
db:
image: mysql:latest
container_name: db
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_DATABASE: test_db
MYSQL_PASSWORD: pass
volumes:
- cookbooks-db:/var/lib/mysql
networks:
- cookbooks
nginx:
image: nginx:alpine
container_name: web-server
restart: unless-stopped
ports:
- "8080:80"
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d/
networks:
- cookbooks
volumes:
cookbooks-db:
networks:
cookbooks:
driver: bridge
Really cant tell where I went wrong, your help is much appreciated!
Please or to participate in this conversation.