Andrew
Andrew

Reputation: 239167

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

Upvotes: 13

Views: 19660

Answers (3)

waspinator
waspinator

Reputation: 6836

copy your .sql or .sql.gz files into the mysql's /docker-entrypoint-initdb.d directory. It will automatically import the data into your database.

https://hub.docker.com/_/mysql

Upvotes: 0

Lauri
Lauri

Reputation: 4679

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

Upvotes: 28

Related Questions