5

I'm trying to test a Django app managed by Docker. Since it's a development project only used by me, I'm using a sqlite3 database backend. However, because I'll be populating this test database with a lot of generated data, and because I don't fully trust Docker, I want to store this sqlite3 db file outside of the container in my home directory, to ensure it doesn't get deleted or lost.

However, by design, Docker makes it difficult for programs inside containers to access files outside of those containers. How do I update my Docker configuration to allow access to this one specific db file in my home directory?

Cerin
  • 60,957
  • 96
  • 316
  • 522

1 Answers1

8

You can mount a host directory into your docker container using -v flag.

For details see this answer: https://stackoverflow.com/a/23455537/7695859.

docker run -v /host/directory:/container/directory -other -options image_name command_to_run

For more details understanding see these official docs.

  1. Use volumes
  2. Manage data in Docker
Emruz Hossain
  • 4,764
  • 18
  • 26
  • I'm using docker-compose, so directly accessing docker isn't quite what I was looking for, but volumes does solve the problem. Thanks. – Cerin Nov 01 '18 at 19:38