eth4io
eth4io

Reputation: 288

How to access sqlite file on host machine from a Docker container using docker-compose?

I have

I want to access the sqlite file from the docker image with the up to date change of sqlite file.

Upvotes: 1

Views: 4240

Answers (1)

Neo Anderson
Neo Anderson

Reputation: 6340

If you have the file on the host machine, you can simply mount that file inside the container, using the -v option. The changes performed by the container on the file will be visible on the host.

Quick proof of concept:

.
├── docker-compose.yml
└── the-file

The docker-compose.yml file:

version: '3'
services:
  the-flask:
    image: python
    volumes:
      - ${PWD}/the-file:/mnt/the-file
    command: tail -f /dev/null

Compose up, get the container ID, then append some text from the container to the file mounted from the host:

docker-compose up -d 

docker exec <container-id> sh -c 'echo "Contend added from container" >> /mnt/the-file'

The file on the host:

cat the-file 
Initial content
Contend added from container

Upvotes: 1

Related Questions