1

I have a flask app in a docker container that writes to a local copy of SQLite db.

what I want to do is move the db out of the container and have it reside on my host. how do I setup docker to run the python code from the container and read and write to the sql lite db on the host.

ronmorg
  • 11
  • 4

2 Answers2

2

Use bind-mount to share host file to container.

If you have the SQLite DB file as app.db, you can run your container with the -v flag (or the --mount flag):

docker run -v /absolute/path/to/app.db:/flask/app/app.db <IMAGE>

Docs: https://docs.docker.com/storage/bind-mounts/

Yuankun
  • 6,875
  • 3
  • 32
  • 34
  • such format will start container with the current host user. while app inside the container is run under flask user. host db file inside the container will be shown as owned by root. and you won't be able to write to db from flask app – Ameba Brain Mar 05 '20 at 23:36
0

You have either

  • setup ownership privileges of your host directory to match uid:gid of the user in the container

or

  • change uid:gid of the user in the container to match numerically uid:gid of your host user who owns directory with sqlite db file

Great answers for both approaches are described here

Ameba Brain
  • 313
  • 1
  • 7