Docker Community Forums

Share and learn in the Docker community.

Wordpress container cannot find sql container when sql respun on another host


#1

Hi,

I am pretty sure I am missing a docker concept here, so hopefully someone can help me out.

My setup is as follows:

    • Docker swarm using several hosts/nodes.
    • One stack with two services: wordpress and sql
    • New overlay network to connect wordpress to sql
    • Wordpress publishes its port to the outside world.

When I deploy the stack the wordpress and sql container are created and they can reach each other perfectly as designed.

When I shut down the node that run sql, a new container is created on another host as replica is set to 1. This works as designed, however, wordpress now gives an error that it cannot connect to the sql server. I assume this is caused by the new sql container which got a new IP-address while wordpress is still looking for the IP-address of the original sql container.

I was expecting that docker would take care of this by using the service name of the docker task.
But here I might get lost…

stack.yml file I use:

version: ‘3.1’

services:
wordpress:
image: wordpress
volumes:
- /mnt/gluster/wordpress_data:/var/www/html
ports:
- 80:80
networks:
- db_network
environment:
WORDPRESS_DB_HOST: wordpress_db
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: password

wordpress_db:
image: mariadb
volumes:
- /mnt/gluster/mysql_data:/var/lib/mysql
networks:
- db_network
environment:
MYSQL_ROOT_PASSWORD: db_root_parola
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: db_password

networks:
db_network:
driver: overlay

Any advice how this should or can work?

Thanks!