MySQL Forums
Forum List  »  Backup

How To Use mysqldump in a Docker Container Using Volumes
Posted by: Ben Lydiard
Date: March 07, 2024 02:56AM

Hi and thanks in advance,

I am trying to use mysqldump to backup the data in a MySQL docker container. I was following the docs here: https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker-mysqldump

I can't copy the instructions exactly because my docker container has its data in a volume (rather than a bind) mount. However I could not see why this would make any difference. I am running two docker containers using docker compose, with the following docker compose file (with irrelevant info removed):

```services:
mysql:
image: 'mysql:8.2.0'
environment:
MYSQL_DATABASE: 'myDb'
MYSQL_ROOT_PASSWORD: 'root'
ports:
- '3306'
networks:
- net1
volumes:
- dataVol:/var/lib/mysql:rw

mysql-backup:
image: 'mysql:8.2.0'
entrypoint: mysqldump -u root --password root --databases myDb --add-drop-database > /path/to/backup.sql
environment:
MYSQL_ROOT_PASSWORD: 'root'
networks:
- net1
ports:
- '3307'
volumes:
- dataVol:/var/lib/mysql:rw

volumes:
dataVol:
driver: local

networks:
net1:
driver: bridge
```

I first then ran (docker compose up) the mysql service (and it works correctly). But then when I run the backup job (docker compose run) I get the error:
`[ERROR] [MY-012574] [InnoDB] Unable to lock ./ibdata1 error: 11`

Upon a Google, this appears to occur when two MySQL instances are working with the same data directory which apparently we should never be doing. Eg the MySQL docs here suggest we shouldn't do this: https://dev.mysql.com/doc/refman/8.0/en/multiple-data-directories.html

So I am now confused because it seems that the MySQL docs are contradicting themselves... Or did I somehow do something different (by using a volume not a bind mount) that is causing my error?

Options: ReplyQuote


Subject
Views
Written By
Posted
How To Use mysqldump in a Docker Container Using Volumes
772
March 07, 2024 02:56AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.