Skip to content

[Howto]: Connect laravel in docker with MySQL on host OS #919

@wcaaan

Description

@wcaaan

Have you already checked elsewhere?

What are you struggling with?

OS / ENVIRONMENT:
Host operating system and version: MacOS Monterey 12.5.1
Docker desktop version: 4.12.0 (85629)
Docker desktop engine: Engine: 20.10.17
Docker desktop compose version: v2.10.2

I'm trying to connect the laravel app inside docker with MySQL on my host machine.

What have you tried already?

On my host machine MySQL is running is connected with following credentials.

Host OS MySQL
MySQL version: 8.0.27
Host: 127.0.0.1
Port: 3307
Password: No password

** Devilbox .env file:**

Expose MySQL Port to Host

HOST_PORT_MYSQL=3306

Laravel .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=hanger
DB_USERNAME=root
DB_PASSWORD=

If i run docker-compose up -d php httpd mysql everything work fine i'm able to connect to database via devilbox phpmyadmin.

As per the documentation https://devilbox.readthedocs.io/en/latest/corporate-usage/use-external-databases.html#database-on-host-os i ran this command docker-compose up -d php httpd bind but i unable to connect to the database from inside the docker to host OS MySQL.

What is your goal?

I want to connect the laravel app in docker with MySQL on my host machine.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions