13

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
Oleg Belousov
  • 9,981
  • 14
  • 72
  • 127
Andrew
  • 227,796
  • 193
  • 515
  • 708
  • Duplicate https://stackoverflow.com/questions/25920029/setting-up-mysql-and-importing-dump-within-dockerfile ? – Metal3d Nov 27 '15 at 16:14

3 Answers3

28

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

Lauri
  • 4,336
  • 3
  • 18
  • 18
3

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

Community
  • 1
  • 1
user2915097
  • 30,758
  • 6
  • 57
  • 59
  • Yes, I've seen those and cannot get them to work. I don't think they work in this instance (also considering running with docker-compose/boot2docker). Can you please provide an example command to run? – Andrew Jun 04 '15 at 00:04
  • Can you provide details about "and cannot get them to work"? Error messages and so. Installating Mysql and then launching a `docker exec -i dump mysql -uroot -proot < dump.sql` looks reasonable. – user2915097 Jun 04 '15 at 05:38
0

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

waspinator
  • 6,464
  • 11
  • 52
  • 78