Mysqldump from Docker container

Hello. Wondering if anyone could help with this, as my understanding of Docker is limited

I’ve been following along with the PHP Novice To Ninja books and have created my own site based on it locally in a Docker container. I know want to extract an SQL file of the database structure to deploy on a web server, but MySQL Workbench (which the book recommends) can’t Data Export with the Docker environment detailed in the book.

So I found the following:

Blockquote

  docker exec -i mysql_container mysqldump -uroot -proot --databases database_name --skip-comments > /path/to/my/dump.sql

I’m just not sure what my relevant fields to fill in are. Here is the docker-compose.yml

Blockquote

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:
    image: phpunit/phpunit:latest
    working_dir: /websites/default
    volumes:
        - ./websites:/websites
    profiles:
        - phpunit
composer:
    image: composer:latest
    working_dir: /websites/default
    volumes:
        - ./websites:/websites
    profiles:
        - composer
maildev: 

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

What that config MySQL workbench should be able to connect to localhost port 3306.

If that doesn’t work, this command should:

docker-compose exec -T mysql mysqldump -uroot -pv.je --databases $DBNAME --skip-comments > /path/to/my/dump.sql

Where $DBNAME must be replaced with the name of the database you want to export. That’s not in the compose file.

1 Like

Hey Thanks.

I went with the folllowing:

Blockquote
docker-compose exec -T mysql mysqldump -uroot -pv.je --databases room4 --skip-comments > /Users/phil/Documents/Web stuff

and got a message saying : service “mysql” is not running container #1

Then you first need to run docker-compose up -d

1 Like

Awesome. Thanks. You are a gentleman and a scholar, and I owe you another one

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.