Run laradock (Docker and Laravel) with mysql local

Asked

Viewed 258 times

0

I had my Laravel environment working at XAMPP. However, given some needs, I had to switch to Docker. For that, I started using Laradock. However, I only want to run php and apache on Docker and not the database, because I want to use the old database (from XAMPP).

Therefore, I have a container of the Laravel running on my computer, so far so good, but when I try to enter the site through the browser, I find the following error:

logo do erro

I imagine the reason for this error is that the container cannot access mysql running on my machine at port 3306, because the credentials in . project env are correct. But I think I’m wrong in this. Anyway, someone can help me?

I can use the database installed on my machine or I will have to create a new one with the command docker-compose up -d mysql?

  • I found in this reply. You need to change the value of the DB_HOST variable in the . env file of your project. Then I changed from "127.0.0.1" to "host.docker.Internal"

1 answer

1

If you are using Docker-Compose, you can also use the host network as the Docker network, which enables your containers within Compose to access host applications. More here.

If you are running pure Docker commands (type Docker run, build etc), you can pass the "-network=host" flag which will have the same effect above.

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.