Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

docker mysql: mysqldump could not create dump file

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading