I have been watching this before. Moving Wordpress site to Docker: Error establishing DB connection
My Linux is centos VM, I try to create WordPress and MySQL(5.6~8). It will be created but I can not connect DB.
This is my command (using swarm).
docker swarm init --advertise-addr=192.168.50.31
docker swarm join --token -secret token- 192.168.50.31:2377
docker network create -d overlay demo
docker service create --name wordpress
-p 80:80 --env WORDPRESS_DB_PASSWORD=root
--env WORDPRESS_DB_HOST=mysql
--network demo wordpress
docker service create --name mysql
--env MYSQL_ROOT_PASSWORD=root --env
MYSQL_DATABASE=wordpress --network demo
--mount
type=volume,source=mysql-data,destination=/var/lib/mysql mysql:5.6
I try to search it why. But did not find the answer.