titra icon indicating copy to clipboard operation
titra copied to clipboard

Persistent docker volume

Open noraj opened this issue 2 years ago • 1 comments

For the default docker compose template, I wanted to point our that there is a third option for data storage.

The docker deployment documentation suggests there are only 2 options:

  • transient Docker volumes, those are volumes create automatically for a container, they will have a unique name like ba40f6e9102380cd8b90b4752433e4914ccdcb11c7bf487743277fd71fc7586c and as far as I remember they will be removed if you do docker-compose down
  • host/container volume mapping, mapping a folder from the host to the container

But there is another way to achieve persistence. There are persistent docker volumes, you can either create them manually with docker volume create or specify them on docker-compose file like below:

version: '3'
services:
  titra:
    image: kromit/titra
    container_name: titra_app
    depends_on:
      - mongodb
    environment:
      - ROOT_URL=${ROOT_URL}
      - MONGO_URL=mongodb://mongodb/titra?directConnection=true
      - PORT=3000
    ports:
      - "127.0.0.1:3000:3000"
    restart: always
  mongodb:
    image: mongo:5.0
    container_name: titra_db
    restart: always
    environment:
      - MONGO_DB:titra
    volumes:
      - titra_mongodb_volume:/data/db
volumes:
  titra_mongodb_volume:

The volume is listed:

$ docker volume ls
DRIVER    VOLUME NAME
local     timesheet_titra_mongodb_volume

This volume is persistent over restart or container removal, it won't be removed with docker-compose down unless you add the -v for volume removal, eg docker-compose down -v.

If you wan I can PR this modified template?

noraj avatar Jul 04 '22 11:07 noraj

Hi, thanks for the Input. Happy to accept any PR adding new deployment options! We will then also update the wiki to reflect this new option.

Thanks, Fabian

faburem avatar Jul 07 '22 07:07 faburem

shipped with titra 0.81.0

faburem avatar Oct 14 '22 14:10 faburem