Reputation: 27
Anyone familiar with using Laravel Sail? I can't find for the life of me figure out why I can't connect to myDb
using the credentials provided when installing Sail.
My DB credentials in the .env
file:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3307
DB_DATABASE=myDb
DB_USERNAME=sail
DB_PASSWORD=password
I've tried:
DB_HOST
back and forth from 127.0.0.1
to localhost
but still getting that same error.DB_HOST
to mysql but still getting that same error.docker ps -a | grep mysql
and the output is: 8b1ef6c28b4e mysql/mysql-server:8.0 "/entrypoint.sh mysq…" 4 minutes ago Up 4 minutes (healthy) 3306/tcp, 33060-33061/tcp, 0.0.0.0:3307->3307/tcp myApp-mysql-1
so no issues with the connection per the output../vendor/bin/sail sail mysql -u root -p
and it allowed me access to mysql on the CLINot sure what else to do. How can I connect to my db in a GUI?
docker-compose.yml
file:
# 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/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3307}:3307'
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: 1
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
networks:
sail:
driver: bridge
volumes:
sail-mysql:
driver: local
Upvotes: 0
Views: 1416
Reputation: 132
Change the DB_HOST
variable to mysql
as the following:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3307
DB_DATABASE=myDb
DB_USERNAME=sail
DB_PASSWORD=password
Upvotes: 1