Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to import SQL file from docker container file system?

I have a docker exec command that tries to import a SQL dump file but it’s complaining about the file not being found.

docker exec $DB_CONTAINER mysql -u root -ptest < /path/to/database.sql

The path is correct (inside the container) but when I investigated why this was not working, I figured that it was trying to look for the file from my host system instead of the container where the file is actually located. How do I import this file and make sure that it looks at the container file system instead of my host file system.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

docker exec $DB_CONTAINER mysql -u root -ptest < /path/to/database.sql

The < is being interpreted by the shell that’s about to execute docker. /path/to/database.sql.

The path is correct (inside the container)

Then the filename has to make it inside the container. You have a few options:

docker exec $DB_CONTAINER sh -c 'mysql -u root -ptest < /path/to/database.sql'

Invoke a shell on the container and have the shell handle the redirection to mysql.

docker exec $DB_CONTAINER mysql -u root -ptest -e "source /path/to/database.sql"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading