For the first time I wanted to use Docker for my Laravel project and I just created the app with newest Laravel 8. I’m using Laravel Sail for starting the Docker. For now, thing goes pretty well, but I don’t know how to connect on MySQL database.
When I start docker with command "sail up", after that how can I make connection on MySQL database with Navicat for example, or even on phpmyadmin?
This is .env content for MySQL:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_example
DB_USERNAME=root
DB_PASSWORD=
2
Answers
To connect to MySQL that is in the Docker container you need to use your machine’s IP.
If you are in a MacOS you can get the IP using the following command:
First of all you need to set DB_HOST=mysql_container_name
Also, you can create phpmyadmin container, add container to the same network and connect with mysql DB, like i did in my docker-compose file: