Container permissions issue

Hi there,

Currently running into an issue while setting up Vikunja. It seems that the container breaks file permissions when updated/restarted. I can OCCASIONALLY access it if I jump into a terminal and run ’ chown 1000 files ’ in the vikunja directory, but this breaks again upon update/restart. Not sure where my issue is lying here as I have followed this guide from the documentation itself.

Docker-Compose:

version: '3'

services:
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: ${PG_PW}
      POSTGRES_USER: ${PG_USER}

    volumes:
      - /path/to/vikunja/db:/var/lib/postgresql/data
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -h localhost -U $$POSTGRES_USER"]
      interval: 2s
    env_file:
      - stack.env
    
  vikunja:
    image: vikunja/vikunja
    environment:
      VIKUNJA_SERVICE_JWTSECRET: ${JWT_SECRET}
      VIKUNJA_SERVICE_PUBLICURL: ${PUBLIC_URL}
      # Note the default path is /app/vikunja/vikunja.db.
      # This config variable moves it to a different folder so you can use a volume and 
      # store the database file outside the container so state is persisted even if the container is destroyed.
      VIKUNJA_DATABASE_PATH: /db/vikunja.db

    ports:
      - 3456:3456
    volumes:
      - /path/to/vikunja/files:/app/vikunja/files
      - /path/to/vikunja/db:/db
    restart: unless-stopped
    env_file:
      - stack.env

Relevant Logfiles:

2024-06-04T10:11:47.568654168Z: INFO	▶ config/InitConfig 001 No config file found, using default or config from environment variables.

2024-06-04T10:11:47.568863446Z: CRITICAL	▶ migration/initMigration 002 Could not connect to db: could not open database file [uid=1000, gid=1000]: open /db/vikunja.db: permission denied

If you chown the files directory, the database file won’t have different permissions as it is located in the db directory. Did you try chown’ing that instead?

Why are you using sqlite when you have postgres container in your deployment?

My apologies, I guess I left out that I did run it on both files AND db. Issue still remains, I can only get it to run if I ‘chown’ it while the container is running. Issues again after restart.

Not quite sure what you mean that I’m using sqlite. I am using postgres and I believe I followed the documentation here correctly for that? Please let me know if I’m missing something

No worries! You need to set the database type to postgres, otherwise Vikunja uses sqlite: Config options | Vikunja

Quoting from the docs you linked:

You’ll also need to change the VIKUNJA_DATABASE_TYPE to postgres on the api container declaration.

Not sure how I glossed over that, I’m sorry!

Seems like I run into a different issue now -

2024-06-04T16:13:14.547064946Z: INFO	▶ config/InitConfig 001 No config file found, using default or config from environment variables.

2024-06-04T16:13:14.54883037Z: CRITICAL	▶ migration/Migrate 003 Migration failed: dial tcp 127.0.0.1:5432: connect: connection refused

info: creating the new user vikunja with 1000:1000

usermod: no changes

2024-06-04T16:13:21.364399998Z: INFO	▶ config/InitConfig 001 No config file found, using default or config from environment variables.

2024-06-04T16:13:21.365406982Z: CRITICAL	▶ migration/Migrate 003 Migration failed: dial tcp 127.0.0.1:5432: connect: connection refused

Did you set the database host?

I would suggest using any of the mariadb examples and then changing the relevant sections for postgres. Quoting from the docs:

The examples on this page use mysql with a mariadb container. To use postgres as a database backend, change the db section of the examples to this:

I notice your volumes are not set, generally if you are wanting to store files in your local dir it would be like this:

volumes:
    - ./files:/app/vikunja/files
    - ./db:/var/lib/postgresql

also, I would check the dockson how to setup postgress db’s:

if your compose still fails, I would add in a config file and drop the env vars, that’s what I had to do to get my instance up:

I notice your volumes are not set, generally if you are wanting to store files in your local dir it would be like this:

Thanks for the help - already aware of this. Just used placeholder values for the actual path. I know it doesn’t matter, it’s all internal, it’s just habit. If you read my reply to the post, it starts, just does not connect to the DB. I just figured /path/to/app/ is a pretty common placeholder and would be understood as such. Sorry for the confusion!

Hopefully I’m failing forward with this and I apologize for my confusion - I do now have it set using VIKUNJA_DATABASE_HOST, with ‘db’ as the variable as that is what the container is named in my stack. This now leads to the error below. As I’m just starting this up, I don’t care about the files at the moment, I nuked /db and /files, and recreated & re-chown’ed them just to rule out any straggling database files confusing it.

vikunja-db-1       | 2024-06-05 17:17:00.216 UTC [664] DETAIL:  Connection matched file "/var/lib/postgresql/data/pg_hba.conf" line 128: "host all all all scram-sha-256"
vikunja-vikunja-1  | 2024-06-05T17:17:00.216787975Z: CRITICAL   ▶ migration/Migrate 003 Migration failed: pq: password authentication failed for user "vikunja"
vikunja-vikunja-1 exited with code 1

Here is my current compose.yaml, changed the paths to environment variables for easier readability here.

version: "3"
services:
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: ${PG_PW}
      POSTGRES_USER: ${PG_USER}
    volumes:
      - ${STRG_PATH}/vikunja/db:/var/lib/postgresql/data
    restart: unless-stopped
    healthcheck:
      test:
        - CMD-SHELL
        - pg_isready -h localhost -U $$POSTGRES_USER
      interval: 2s
    env_file:
      - .env
  vikunja:
    image: vikunja/vikunja
    environment:
      VIKUNJA_SERVICE_JWTSECRET: ${JWT_SECRET}
      VIKUNJA_SERVICE_PUBLICURL: ${PUBLIC_URL}
      # Note the default path is /app/vikunja/vikunja.db.
      # This config variable moves it to a different folder so you can use a volume and 
      # store the database file outside the container so state is persisted even if the container is destroyed.
      VIKUNJA_DATABASE_PATH: /db/vikunja.db
      VIKUNJA_DATABASE_TYPE: ${DB_TYPE}
      VIKUNJA_DATABASE_HOST: ${DB_HOST}
    ports:
      - 3456:3456
    volumes:
      - ${STRG_PATH}/vikunja/files:/app/vikunja/files
      - ${STRG_PATH}/vikunja/db:/db
    restart: unless-stopped
    env_file:
      - .env
networks: {}

not sure if this will help, but you may need to add:

      VIKUNJA_DATABASE_USER: vikunja
      VIKUNJA_DATABASE_PASSWORD: ${SUPERSECRET} 

I also found in the config SSL certs(if you use this) specifically for postgres DB users:

Hope I have helped and not just caused noise on this post!

not sure if this will help, but you may need to add:

      VIKUNJA_DATABASE_USER: vikunja
      VIKUNJA_DATABASE_PASSWORD: ${SUPERSECRET} 

THANK YOU!! Evidently I am terrible at reading, I guess I glossed over this too in the documentation. That confirmed my confusion - digging through logs I saw it trying to use ‘postgres’ as the user but for the life of me I couldn’t wrap my head around why. D’oh. I’m so sorry for the dumb questions!

To the both of you - thank you so much. Really excited to use this project. Have a wonderful week!

Edit: In case anyone stumbled on this in the future, using my example above, I just used the same .env variables I used for the postgres container in the stack.

My current compose.yaml now looks like this:

version: "3"
services:
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: ${PG_PW}
      POSTGRES_USER: ${PG_USER}
    volumes:
      - ${STRG_PATH}/vikunja/db:/var/lib/postgresql/data
    restart: unless-stopped
    healthcheck:
      test:
        - CMD-SHELL
        - pg_isready -h localhost -U $$POSTGRES_USER
      interval: 2s
    env_file:
      - .env
  vikunja:
    image: vikunja/vikunja
    environment:
      VIKUNJA_SERVICE_JWTSECRET: ${JWT_SECRET}
      VIKUNJA_SERVICE_PUBLICURL: ${PUBLIC_URL}
      # Note the default path is /app/vikunja/vikunja.db.
      # This config variable moves it to a different folder so you can use a volume and 
      # store the database file outside the container so state is persisted even if the container is destroyed.
      VIKUNJA_DATABASE_PATH: /db/vikunja.db
      VIKUNJA_DATABASE_TYPE: ${DB_TYPE}
      VIKUNJA_DATABASE_USER: ${PG_USER}
      VIKUNJA_DATABASE_PASSWORD: ${PG_PW}
      VIKUNJA_DATABASE_HOST: ${DB_HOST}
    ports:
      - 3456:3456
    volumes:
      - ${STRG_PATH}/vikunja/files:/app/vikunja/files
      - ${STRG_PATH}/vikunja/db:/db
    restart: unless-stopped
    env_file:
      - .env
networks: {}
1 Like

:clinking_glasses: Cheers! Glad I could help!

1 Like