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.

  • How did you configure networking on the Docker container host? – Michael Hampton Nov 25 '18 at 13:04
  • @MichaelHampton I am just using default networking. There is no firewall or IP table limiting inbound traffic to the host server. In this case, the 801 port is as a result open to the public. Thoughts? – A br Nov 25 '18 at 21:32

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.

  • thanks for the feedback. But I thought that the parameter -e WORDPRESS_DB_HOST is going to override the IP address of the database server for Wordpress? If so, shouldn't this work? My DB server is sitting in another VM with a separate IP, but that IP is accessible by the wordpress container, it is just that the container's setup seems to be ignoring the WORDPRESS_DB_HOST parameter – A br Nov 26 '18 at 2:41
  • @Abr You're talking about something else entirely, which is irrelevant to the problem or the solution. – Michael Hampton Nov 26 '18 at 4:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.