Wordpress Example in Docker compose fails

I’m learning Docker and am to the point where I can start 1 container with no problems… so I thought I’de start working on something using 2 containers and I’m a little more familiar with. I am trying to step through the example at https://docs.docker.com/compose/wordpress/ (i copied it exactly) and can get the containers to build and start with no issue… .but something is amiss…

I get the following error when viewing the logs on the wordpress container.
Warning: mysqli::mysqli(): (HY000/1045): Access denied for user ‘root’@‘’ (using password: YES) in - on line 22

when I login to the console of the mysql db - it doesn’t like the password that is specified in the yml file (trying with mysql -u root -p) and it generates the error ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

any tips? I’m going crazy trying to figure out why the example doesn’t work.

running on Ubuntu

If you are using docker-compose still and the docker-compose.yml was copied exactly, then the MySQL root password should be wordpress. Looks like your WordPress container is attempting to login to MySQL as root which is okay and again expected if you are following the example exactly.

The command to login to MySQL from inside the container should be mysql -u root -pwordpress. This fails?

Also, try specifying an explicit tag for WordPress in docker-compose.yml, like image: wordpress:php7.1. Just checked and a tag with -fpm is latest, I recall this threw a wrench in things when I was playing with this a while back.

yup… copied the example exactly issuing this from the mysql container cli and i get…

root@43a759f6ae7b:/# mysql -u root -pwordpress
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

The mysql environment variables are;
MYSQL_USER: wordpress

I just can’t explain why I can’t login to the mysql db - I’m going nuts here.

Solved the mystery (for anyone else that runs into it)

The example file has a volume defined;
- db_data:/var/lib/mysql

when you change that to something other than /var/lib/mysql it seems to work fine. I don’t understand enough yet to know why it does’t work with default path, but changing it to - db_data:/var/lib/mysql2 allows it to work fine.


You’ve saved my life <3

1 Like

That really does work, but it’s bothering me. WHY does this work? Haha, oh well. Thank you rbrynaphis, you saved me a lot of time!

May I suggest that if you have another docker instance set up to go to that db_data then there will be some sort of conflict? Thats my best theory.

Thank you , you also saved my life

thank you very much, you saved me a lot of time