5

I am looking to connect a PhpMyAdmin running in a container (Docker) to a MySQL server running on the host and listening on 127.0.0.1.

However, when I give docker the varuable -e PMA_HOST=127.0.0.1, it only look on it's own Docker network... How would I be able to talk to my host MySQL DB server ?

yield
  • 264
  • 4
  • 13
  • 1
    Possible duplicate of [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – yamenk Dec 04 '17 at 12:27

2 Answers2

4

You shouldn't use 127.0.0.1 as IP address to refer to the host as that will point to the docker container where phpAdmin is running.

You need to find the IP address of the host on the docker0 interface as use that ip instead. You can do that using:

-e PMA_HOST=$(ip route show | grep docker0 | awk '{print $9}')
yamenk
  • 46,736
  • 10
  • 93
  • 87
0

If your mysql is on your host, without a domain name, you won't be able to access it from a container. Maybe with a bridged network. You should try to move the database to a container. It will be super easy to connect the phpmyadmin then.

Fiber Optic
  • 184
  • 5