Xrabackup2.4 in docker container Failed to connect to MySQL server 5.6 that runs in docker container

Hello,
I have a docker container with MySQL 5.6 and Percona Xtrabackup 2.4 that runs in docker container either.
MySQL 5.6 comtainer was created with docker-compose.yml file:

Xtrabackup docker container was created with the command:
version: ‘3’
services:
mysql56:
image: mysql:5.6
restart: unless-stopped
container_name: mysql56-container
ports:
- “127.0.0.1:3306:3306”
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWD}
volumes:
- /usr/local/docker-custom/mysql56-container/mysql/conf.d:/etc/mysql/conf.d
- ${DB_VOLUME}:/var/lib/mysql
- /home/${MY_USER}/support:/home/support
- /home/${MY_USER}/backups:/home/backups

Xtrabackup 2.4 container was created with the below command:

docker create
–name xtrabackup24-container
–volumes-from mysql56-container
percona/percona-xtrabackup:2.4
xtrabackup
– defaults-file=/etc/mysql/ conf.d/my-32G.cnf`
–host=localhost --port=3306
–socket=/var/run/mysqld/mysqld.sock \
–backup --datadir=/var/lib/mysql
–target-dir=/home/backups/xtrabackup
–user=root --password=root_password

When I start xtrabackup with the command:
$ docker start -ai xtrabackup24-container

xtrabackup tryes to connect to MySQL 5.6 server:
Connecting to MySQL server host: localhost, user: root, password: set, port: 3306, socket: /var/run/mysqld/mysqld.sock

Failed to connect to MySQL server: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

When I change the server IP to the IP the MySQL5.6 container runs on:
$ docker inspect mysql56-container | grep “IPAddress”
“SecondaryIPAddresses”: null,
“IPAddress”: “”,
“IPAddress”: “172.19.0.2”,

The connection erroris Failed to connect to MySQL server: Can’t connect to MySQL server on ‘172.19.0.2’ (110)

What am I doing wrong?

Any help is highly appreciated.

Regards, geneva_nn

2 Likes

Hi There,

Make sure MySQL container is listening on all interfaces, not only loopback:

[mysqld]
bind-address = 0.0.0.0
1 Like

Thank you for the advice.

Tried bind-address=0.0.0.0, tried to remove bind-address, no results. Still getting cannot connect to MySQL error.

1 Like

HI @geneva_nn your issue is intra container communication. You must configure your docker network so one container can communicate with the network interface of the other. Once they are able to communicate (ping each other), you just need to make sure mysql is also binding on that interface.

Please check Networking with standalone containers | Docker Documentation

1 Like

Hi, @Marcelo_Altmann ,
I have found a reason and resolved the MySQL xtrabackup connection issue.

The reason was the xtrabackup 2.4 in docker container could not see the MySQL 5.6 socket (MySQL 5.6 is in own docker container).
What I have done:

  1. mounted a host /var/run/mysqld folder to the MySQL 5.6 container socket folder /run/mysqld. The socket inside of the MySQL56 container is really located inside of the /run/mysqld folder.
    Here is a docker-compose.yml file part for the MySQL 5.6 container mysqld volume:
    volumes:

    - /var/run/mysqld:/run/mysqld
  2. Created xtrabackup 2.4 docker container with the --socket=/run/mysqld/mysqld.sock option:
    docker create
    –name xtrabackup24-container
    –volumes-from mysql56-container
    percona/percona-xtrabackup:2.4
    xtrabackup
    –defaults-file=/etc/mysql/conf.d/my-32G.cnf
    –socket=/run/mysqld/mysqld.sock
    –backup --datadir=/var/lib/mysql
    –target-dir=/home/backups/xtrabackup
    –user=backup_user_name --password=backup_user_password
1 Like