Docker – How to Import Data into MariaDB Instance

dockermariadb

I'm setting up a server to host a wordpress site and I have wordpress + mariadb + nginx all running in Docker very well. I can create and configure a new site in WordPress and its all successful.

I'd like to import some pre-existing site data into the Mariadb instance, and because its in a Docker container, it is effectively isolated from any data manipulation utilities. Obviously that's great for security, but what's the best way of making something in docker "visible" to localhost (or even externally) so I can connect up the mysql client?

Best Answer

You can publish your MariaDB port by running:

docker run -p3306:3306 mariadb

This way you can access to mariadb instance by connecting to dockerhost:3306.

Anyway if you only have to import sql data files, I suggest you to use docker exec utility and using the container mysql client for importing that data. For example:

docker exec -i mariadb_container mysql -uroot -pmypassword mydb < /path/inside/host/data.sql