Docker-Compose WordPress MySql Can't Connect
WARNING: This was the only container I had on my server so I did not mind deleting everything. Running these commands blindly can wipe out all your docker containers, volumes, etc.
I was able to solve my problem by deleting the docker volume.
Even when you run this command:
$ docker-compose stop && docker-compose rm -v
does not remove volumes.
Every time I tried to create a new docker container it used my old volume that stored my old mysql database with my old mysql users table thus my old password which I would change and was wrong.
to get rid of old docker volumes use:
docker volume rm $(docker volume ls -q )
will remove all docker volumes. then rebuild which will create a new volume with an updated table from your env
variables.
A working example with modifications to your docker-compose: https://github.com/sahil87/wordpress-mysql-docker/blob/master/docker-compose.yml
Changes:
Make the WORDPRESS_DB_HOST
WORDPRESS_DB_HOST: foldername_db_1.foldername_default:3306
This seems to be recent change in the way either docker-compose works or just the mysql image, as even I am using only that. Couldn't find any documentation on it :( , took 2 days to figure out. Hope this saves you some time!