Backup Database from A Docker Container

Hello,

I’m trying to backup a database I’ve created locally on a docker container following the description in MySql NOvice To Ninja book.

On my previous Mac I used the following command whilst the container is running to create a backup:

docker-compose exec -T mysql mysqldump -uroot -p$PASSWORD --databases $DATABASE --skip-comments > /Path/to/folder/dump.sql

However on my new mac I get the following in the sql file and nothing else:

OCI runtime exec failed: exec failed: unable to start container process: exec: “mysqldump”: executable file not found in $PATH: unknown

Any ideas or workarounds?

That command looks correct. Which docker container are you using for mysql?

Docker is a bit of a mystery to me, I’ve just followed the instructions in the book until they don’t work.

So I can’t answer your question with any certainty, but I would guess at ‘mariadb’. Here is my docker-compose.yml:

version: '3.8'
services:
    updatecerts:
        image: vjedev/certupdater:latest
        volumes:
            - certs:/certs
            - mysqlconf:/mysqlconf
    landingpage:
        image: vjedev/landingpage:latest
        volumes:
            - ./websites:/websites
    databaseimportexport:
        image: vjedev/database-import-export:latest
        volumes:
            - ./websites:/websites
        depends_on:
            - mysql
    web:
        image: nginx:latest
        ports:
            - "80:80"
            - "443:443"
        volumes:
            - ./nginx.conf:/etc/nginx/conf.d/nginx.conf
            - certs:/certs
            - ./websites:/websites
        depends_on:
            - updatecerts
    php:
        build:
            context: .
            dockerfile: PHP.Dockerfile
        volumes:
            - ./websites:/websites
    mysql:
        image: mariadb:latest
        environment:
            MYSQL_ROOT_PASSWORD: 'v.je'
            MYSQL_USER: 'v.je'
            MYSQL_PASSWORD: 'v.je'
        volumes:
            - mysqldata:/var/lib/mysql
            - certs:/ssl
            - mysqlconf:/etc/mysql/conf.d/
        ports:
            - 3306:3306
    phpunit:
        build:
            context: .
            dockerfile: PHP.Dockerfile
        working_dir: /websites/default
        entrypoint: 'vendor/bin/phpunit'
        volumes:
            - ./websites:/websites
        profiles:
            - phpunit
    composer:
        build:
            context: .
            dockerfile: PHP.Dockerfile
        working_dir: /websites/default
        entrypoint: /usr/bin/composer
        volumes:
            - ./websites:/websites
        profiles:
            - composer
    maildev:
        image: maildev/maildev:latest

volumes:
    mysqldata: {}
    certs: {}
    mysqlconf: {}```

You are indeed using mariadb there. mysqldump is deprecated for MariaDB, maria-dump should be used instead.

See https://mariadb.com/kb/en/mysqldump/

2 Likes

Thanks so much

mariadb-dump

did the trick

1 Like