'Embed sqlite database to docker container?

I'm new to Docker. Is it possible to embed a sqlite database in a docker container and have it updated every time my script in that container runs?



Solution 1:[1]

Dockerfile example to install sqlite3

FROM ubuntu:trusty
RUN sudo apt-get -y update
RUN sudo apt-get -y upgrade
RUN sudo apt-get install -y sqlite3 libsqlite3-dev
RUN mkdir /db
RUN /usr/bin/sqlite3 /db/test.db
CMD /bin/bash

persist the db file inside host OS folder /home/dbfolder

docker run -it -v /home/dbfolder/:/db imagename

Solution 2:[2]

If you want to persist the data in sqlite, use host directory/file as a data volume Refer "Mount a host directory as a data volume" section in https://docs.docker.com/storage/volumes/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Avinash Raj
Solution 2 Benjamin W.