Docker Community Forums

Share and learn in the Docker community.

Unable to complete documentation tutorial - access denied to log into mysql database


(Linucksrox) #1

Hi there,

I’m trying to work through the examples in the documentation for managing secrets with a Wordpress service (https://docs.docker.com/engine/swarm/secrets/#advanced-example-use-secrets-with-a-wordpress-service). At the stage where I start up the Wordpress service, it continuously fails and the logs state that the mysql service is denying access.
I also tried firing up an Adminer instance but am unable to log into the database using either the Wordpress username/password or the root username/password.
I’m probably just missing something stupid, but I’m just asking for some help finding my mistake.

Here’s exactly what I tried, in this order, starting from a blank slate:

docker swarm init

docker network create -d overlay mysql_private

echo "somewordpresspassword" | docker secret create mysql_password -

echo "abetterrootpassword" | docker secret create mysql_root_password -

docker service create \
--name mysql \
--replicas 1 \
--network mysql_private \
--mount type=volume,source=mydata,destination=/var/lib/mysql \
--secret source=mysql_root_password,target=mysql_root_password \
--secret source=mysql_password,target=mysql_password \
-e MYSQL_ROOT_PASSWORD_FILE="/run/secrets/mysql_root_password" \
-e MYSQL_PASSWORD_FILE="/run/secrets/mysql_password" \
-e MYSQL_USER="wordpress" \
-e MYSQL_DATABASE="wordpress" \
mysql:latest

docker service create \
--name wordpress \
--replicas 1 \
--network mysql_private \
--publish published=80,target=80 \
--mount type=volume,source=wpdata,destination=/var/www/html \
--secret source=mysql_password,target=wp_db_password,mode=0400 \
-e WORDPRESS_DB_USER="wordpress" \
-e WORDPRESS_DB_PASSWORD_FILE="/run/secrets/wp_db_password" \
-e WORDPRESS_DB_HOST="mysql:3306" \
-e WORDPRESS_DB_NAME="wordpress" \
wordpress:latest

At this point, the Wordpress service keeps failing and restarting with the error message task: non-zero exit (1), so I ran

docker service logs wordpress

And the resultant logs show many lines like this:

MySQL Connection Error: (1045) Access denied for user ‘wordpress’@‘10.0.12.2’ (using password: YES)

I get the same error message when attempting to log in from Adminer (having joined the same overlay network). What am I missing?


(Linucksrox) #2

Nevermind, the problem seems to have “solved itself.” Realistically I think the problem was something to do with not cleaning up the old volumes when I was removing services and trying to recreate them (using the old volume mounts). I’m currently documenting a process for clearing out everything in order to reset to a “stock” state for going through other tutorials, basically this:

docker service rm wordpress

docker service rm mysql

docker network prune

docker volume prune