Categories: php, mysql, wordpress, docker

docker wordpress container can't connect to mysql container

1 answer

I'm at a loss here as to not only why this isn't working but how to further troubleshoot it. I'm new to docker, so could be something obvious, but I can't find it. I did look over some other links here which could be considered "duplicate questions" and nothing helped.

My playground setup:

mysql container named: "db"
phpmyadmin container named: phpmyadmin
wordpress container named: domain-blog

All containers are in a bridge network docker0

At this stage I'm starting all containers individually, but I am ensuring the database is up and running prior to running wordpress.

The string to start the wordpress container:

docker run --name="domain-blog" -d \ -e WORDPRESS_DB_HOST=db:3306 \ -e WORDPRESS_DB_USER=domain_user \ -e WORDPRESS_DB_PASSWORD=testedpassword \ -e WORDPRESS_DB_NAME=domain_blog \ -e WORDPRESS_TABLE_PREFIX=astring \ --network=docker0 \ -p 8081:80 \ --restart always \ wordpress 

What I've tried:

  • I can log in as root with rootpassword from phpmyadmin navigating via hostip:8080.
  • I can log in as domain_user, using the testedpassword from phpmyadmin.
  • Confirmed I can add a new table when logged in as domain_user.
  • I have spun up an ubuntu container and installed network tools, can ping all containers.
  • I installed iputils-ping directly on the wordpress container and can ping db using ping db. Ping is hitting, but also confirmed that the db is resolving to the correct ip address.
  • cat wp-config.php shows that user, host(db:3306), password, and database are all being passed through as I'd expect.

I used phpmyadmin when I created the new user/password, database, and added permissions for the user to that database. The user is set to log in from %.

The error I'm getting on not being able to access the database is when trying to navigate to the blog via hostip:8081 Exact error: Error establishing a database connection

Received answer to this question:
The best answer according to the author of the question:

Solved it and feeling rather dumb about it, but in the spirit of education...

When I entered the username/password into mysql via phpmyadmin, the default in the admin interface is to use Caching sha2 authentication.

I reset the password using Native Mysql Authentication... It works no problem now.