docker mysql: mysqldump could not create dump file.
docker-compose.yaml
version: "3"
services:
mysql:
container_name: mysql
image: mysql:8.0.33
environment:
- MYSQL_ROOT_PASSWORD=123456
user: 115:115
volumes:
- ./backup:/opt/backup
Tried:
sudo docker exec mysql mysqldump -u root -p123456 --no-tablespaces --databases my_db > /opt/backup/my_db.sql
Error:
-bash: /opt/backup/my_db.sql: No such file or directory
The directory is there by:
sudo docker exec mysql ls -l /opt/backup
The owner of the directory is 115:115 (mysql). files can be created under the directory:
sudo docker exec mysql touch /opt/backup/foo.txt
If dump to current directory without directory "/opt/backup", no error message. But the dumped file could not be found under root directory. (current directory is root seen by "sudo docker exec mysql pwd").
Similarly, if dump to /tmp directory, no error message, but no file is created under the /tmp.
sudo docker exec mysql mysqldump -u root -p123456 --no-tablespaces --databases my_db > /tmp/my_db.sql
What is the way to dump mysql data from mysql docker container?
with >
you are currently redirecting the output to the host's /opt/backup/my_db.sql
not within the container
try:
docker exec mysql bash -c 'mysqldump -u root -p123456 --no-tablespaces --databases my_db > /opt/backup/my_db.sql'