Issues with WordPress container configured for external database host

A br asked:

I am trying to run the WordPress container, configured to use an external MySQL database server like so:

docker run --name wordpress1 -p 801:80 -e WORDPRESS_DB_HOST=MYDBSERVERIPADDRESS:3306 -e WORDPRESS_DB_USER=username -e WORDPRESS_DB_PASSWORD=password -e WORDPRESS_DB_NAME=dbname -it wordpress

However, when I do so I get this error:

MySQL Connection Error: (1045) Access denied for ‘username’@’WRONGIPADDRESS’ (using password: YES)

The problem is that it is using the IP address of the container host (what I listed as WRONGIPADDRESS), not the IP address that I specified using the WORDPRESS_DB_HOST parameter – it is essentially ignoring the WORDPRESS_DB_HOST parameter completely.

Any idea why this would be happening? This is supposed to be a fully supported -e parameter to a very popular container, WordPress, so any help you can provide is greatly appreciated.

My answer:


By default the Docker internal bridge network, on the docker0 interface, uses NAT to communicate with hosts outside the container host. So the IP address that external hosts see is that of the container host, not of the individual container. The address you call “wrong” is actually the expected address, because your MySQL server is not running in another Docker container on the host, but is outside. You should fix the user’s IP address in the MySQL user table.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.