Search code examples
node.jsdockersqlitedocker-composeprisma

Trying to persist docker container data


I want to Persist my sqlite database between container restarts and new image pulls

Hi,

I have this docker-compose.yml file:

services:
  myservice:
    image: myimage
    container_name: thecontainername
    volumes:
      - ./app.db:/prisma/app.db
    restart: always
  watchtower:
    image: containrrr/watchtower
    container_name: watchtower
    labels:
      - "com.centurylinklabs.watchtower.enable=false"
    environment:
      - REPO_USER=${DOCKERHUB_USER}
      - REPO_PASS=${DOCKERHUB_PASS}
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command: --cleanup --interval 120 --debug
    restart: always

Sqlite database is persisted between container restarts but not when pulling a new image manually via command or automatically with watchtower.

How could this be resolved ?


Solution

  • From the follow up, it appears you were mounting the wrong path inside the container. This is shown with the files that have been changed in the container filesystem (displayed with docker diff) not matching the path of the volume mount.

    Typically, you do not want to mount mutable files directly in the container, and instead want to mount the entire directory. This is because many tools that modify files do so by creating a new temporary file, and then renaming it to overwrite the existing file. That process creates a new inode, and volume mounts are bound to the inode, resulting in any changes inside the container, or outside the container, not being reflected on the other side or between container restarts.