Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import a database into a Docker container using docker-compose

I am working with the official WordPress Docker image with docker-compose on my Mac (using boot2docker). I need to do a one-off data import. I'm not sure how to do this. How can I import data to the database container?

wordpress:
  image: wordpress
  links:
    - db:mysql
  ports:
    - 8080:80
  volumes:
    - .:/var/www/html/wp-content/themes/my-theme-name

db:
  image: mariadb
  environment:
    MYSQL_ROOT_PASSWORD: example
like image 495
Andrew Avatar asked Jun 03 '15 08:06

Andrew


People also ask

Can I store database in Docker?

If you're working on a small project, and are deploying to a single machine, it's completely okay to run your database in a Docker container. Be sure to mount a volume to make the data persistent, and have backup processes in place. Try to restore them every once in a while to make sure your backups are any good.


2 Answers

When using official Wordpress image, default name of the created database is wordpress.

So after you have deployed Wordpress application with docker-compose, you can import your wordpress database by

docker exec -i db mysql -uroot -pexample wordpress < dump.sql

like image 67
Lauri Avatar answered Sep 28 '22 06:09

Lauri


See this doc http://depressiverobot.com/2015/02/19/mysql-dump-docker.html and also this previous on SO Setting up MySQL and importing dump within Dockerfile

like image 23
user2915097 Avatar answered Sep 28 '22 07:09

user2915097