This is a simple way of importing MySQL database in Docker.
-
In you Dockerfile you must have a shared folder. Shared folder is a directory in your host machine that is mounted to Docker instance.
-
Put the exported sql file in the shared folder.
-
Login to your Docker instance via
docker exec -it DOCKER_CONTAINER_ID bin/bash
. -
Login to MySQL via
mysql -u USERNAME -p
. -
While in MySQL CLI, create a database via
create database DB_NAME;
. -
While in MySQL CLI, use the database you just created via
use DB_NAME;
. -
While in MySQL CLI, import the sql file via
source /path/to/file.sql
.
Done
@Itsmedontworry it means your backup file
From left to right:
docker It's the docker command
exec When you want to run something in the container
mysql_container It's your container’s name
mysql It's the command itself like
mysql --version
-u It asks for your MySQL user like
-uroot
-p It asks for your MySQL password like
-ppassword
database It's your database name, previously created
database_backup.sql It's the backup file you want to import