When logging the user I am having this problem with Laravel 7. All the data in my database seems to be correct. I use port 3307 and I am using Docker for the project.
My .env are:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3307
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
For the mysql service in docker I use:
version: '3'
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: e-learning-app_nginx
ports:
- "8087:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7
container_name: e-learning-app_mysql
restart: always
tty: true
ports:
- "3307:3306"
environment:
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
volumes:
- ./mysql:/var/lib/mysql
php:
build:
context: .
dockerfile: Dockerfile
container_name: e-learning-app_php
volumes:
- ./src:/var/www/html
ports:
- "9007:9000"
networks:
- laravel
Edit: I put the docker-compose.yml
complete.
I do not know what is the problem. The strange thing is that the migrations run fine for me and from client to db I can connect everything fine. I already tried clearing cache of routes and configurations... I'm using auth.
In my local environment I also use Docker Compose for projects with Laravel. Try using the container name as
DB_HOST
. For more information, you can consult the documentation on this here .DB_HOST=mysql
If your MySQL database is called homestead you should not have a problem, if it has another name you must change it in the configuration to the database in the .env file
The error is because the database with the name "homestead" does not exist.
Solution 1:
Hello, try changing your file
.env
so that instead of127.0.0.1
connect withlocalhost
as follows:Then from the container execute:
Solution 2:
If that didn't work then modify your file
config/database.php
and addThen from the container execute:
This answer was given on Stackoverflow in English and I have tried to adapt it for your case.
SOLVED! although I don't know if in the most " correct " way.
I detail the steps that led me to the solution:
docker inspect container_id
(at the end of the json).env
that IP as host instead of 127.0.0.1 or localhostDB_HOST=172.18.0.1
docker-compose.yml
service for artisandocker-compose down
and thendocker-compose up
(maybe it's better to delete the containers and volumes to start clean)Artisan service added in
docker-compose.yml
:My
Dockerfile
:Then the logging issue was fixed and I was able to perform the migrations and seeds using artisan from the container:
docker-compose run --rm artisan migrate --seed
To connect from an external client like TablePlus I make the connection with the data:
To access the app I still use
http://127.0.0.1:8087
orhttp://localhost:8087
.Everything working fine.
The docker that I am using to mount the project can be found at https://github.com/diegoulloao/laravel-docker-startpoint