I’m running a MySQL instance in compose, with port 3306 exposed. I’m trying to figure out how I can use XtraBackup via docker to connect to the container. I’m running:
docker run --name pxb --volumes-from gpv1-mysql -v backupvol:/backup_84 -it --user root percona/percona-xtrabackup:8.4 /bin/bash -c "xtrabackup --backup --datadir=/var/lib/mysql/ --target-dir=/backup_84 --user=root --password=test123; xtrabackup --prepare --target-dir=/backup_84"
It finds the container, but fails to connect to MySQL with the error
[Xtrabackup] Failed to connect to MySQL server: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
I’m not great at the networking part of docker and would love advice on how to proceed.
Use the -h
flag on xtrabackup to specify the MySQL server. Typically this is localhost.
Thanks. I updated the command to
docker run --name pxb --volumes-from gpv1-mysql -v backupvol:/backup_84 -it --user root percona/percona-xtrabackup:8.4 /bin/bash -c "xtrabackup --backup --datadir=/var/lib/mysql/ --target-dir=/backup_84 --host=localhost --port=3306 --user=root --password=test123; xtrabackup --prepare --target-dir=/backup_84"
but still no luck. I also tried 127.0.0.1 in case. If it helps, I’m running MySQL in my compose file as
mysql:
container_name: gpv1-mysql
ports:
- "127.0.0.1:3306:3306"
I’d appreciate any additional advice.
Please check this option: i.e. --network container:<name|id>
Like :
docker run --rm --name pxb \
--volumes-from gpv1-mysql \
-v backupvol:/backup_84 \
--network=container:gpv1-mysql \
-it --user root \
percona/percona-xtrabackup:8.4 \
/bin/bash -c "xtrabackup --backup --datadir=/var/lib/mysql --target-dir=/backup_84 --user=root --password=test123; xtrabackup --prepare --target-dir=/backup_84"
1 Like
Still no luck. I added the hostname and port:
docker run --rm --name pxb \
--volumes-from gpv1-mysql \
-v backupvol:/backup_84 \
--network=container:gpv1-mysql \
-it --user root \
percona/percona-xtrabackup:8.4 \
/bin/bash -c "xtrabackup --backup --datadir=/var/lib/mysql --target-dir=/backup_84 --host=localhost --port=3306 --user=root --password=test123; xtrabackup --prepare --target-dir=/backup_84"
Still says it can’t connect to mysql on localhost. Given this is a command being run in a container, won’t it need to find the host localhost:3306? I’m not sure how to tell it to look there.
Hi @rsodhia
Could you try next commands on your server?
docker network create \
--driver bridge \
--subnet 172.20.0.0/16 \
custom_default_net
docker run -d \
--network custom_default_net \
--name percona-server \
-e MYSQL_ROOT_PASSWORD=root \
-v percona-data:/var/lib/mysql \
--platform "linux/amd64" \
-p 3306:3306 \
percona/percona-server:8.4.5
docker run --rm \
--network custom_default_net \
--name pxb \
--volumes-from percona-server \
-v backupvol:/backup_84 \
-it --user root \
percona/percona-xtrabackup:8.4 \
/bin/bash -c "xtrabackup --backup --datadir=/var/lib/mysql --target-dir=/backup_84 --host=localhost --port=3306 --user=root --password=root; xtrabackup --prepare --target-dir=/backup_84"