Here’s how to run sql file inside a docker container in a laravel project. But before we start, I assume you already have a dockerize laravel project in your local. If not you may follow my previous tutorial http://safventure.live/dockerize-existing-laravel-project.
Procedure:
- Place your sql file in your laravel root folder
- Copy the SQL file into the mysql docker container by executing the command below.
docker cp laravel-task_db laravel_mysql:/laravel-task_db
laravel-task_db.sql – sql file
laravel_mysql – name of my mysql container
- Launch a mysql bash terminal inside your docker container by executing the commands below.
docker ps – copy the the container_id of laravel_mysql
docker exec -it [mysql_container_id] bash
- Login to MySql
mysql -u root -p (default password is password)
show databases;
use laravel;
– laravel is the name of our database
source laravel-task_db.sql
– execute this command to run the sql file
Note: To run sql file in postgre, execute command below:
psql laravel_mysql < laravel-task_db.sql