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

All answers to this question, which has the identifier 61239252

The best answer:

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.

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type is referenced as an interface from”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data