I am working with PhpStorm 2018.3.4, Docker, MySQL and Ubuntu.
I tried unsuccessfully to configure MySQL with the Docker container network_mysql
.
First, I have tried this configuration :
It gave me this error :
Then, I tried this :
This one gave me this other error.
Am I missing something? Is there another place where I must configure something?
docker ps
output :
Here docker network ls
:
For the command docker inspect network_mysql
, here is a link to the description :
https://pastebin.com/9LmeAkc8
Here is a docker-compose.yml configuration : https://pastebin.com/DB4Eye4y
I tried to put - "3306:3306"
in addition to the wex_server_proxy
section with no avail.
The file to modify was this one :
I added the ports
section, opening the 3306 port :) And then, it works.
I notice that you are not mapping the mysql container port out. If you did, you would see this from the docker ps
command:
... 0.0.0.0:3306->3306/tcp network_mysql
The container network_mysql
is attached to a bridge type network called tmp_wex_net
. This means that the container is not accesible from the host, by its container name.
I appears that you are using a docker-compose.yml definition for the stack. In order to be able to access the container from the host, you need to use the ports
section of your compose definition for this container:
serivces:
mysql:
...
ports:
- "3306:3306"
...
If you are starting it with docker run
, then you can acomplish the same thing with:
docker run -p 3306:3306 --name network_mysql --network="tmp_wex_net" -d mysql
And then use localhost
in the hostname of your connection settings in PHPStorm. Like this:
Host: localhost
Port: 3306
Database: network
The reason that you are not able to connect, is that the host name network_mysql
that you specify in the connection settings, does not resolve to any host that your machines knows of.
The container name of a docker container, is not a DNS name that the docker host can resolve.
If you have not specified any network for your mysql container, then it is connected to the default bridge network. And if you have created a new network, without specifying the type - it will also default to the bridge driver.
In order to access the container from the host, you need to either:
localhost:<portnum>
from the host machine.