Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Bug report) Docker Compose file needs to be updated #2239

Open
1 task done
Unrepentant-Atheist opened this issue Oct 16, 2021 · 14 comments
Open
1 task done

(Bug report) Docker Compose file needs to be updated #2239

Unrepentant-Atheist opened this issue Oct 16, 2021 · 14 comments

Comments

@Unrepentant-Atheist
Copy link

Unrepentant-Atheist commented Oct 16, 2021

Preflight Checklist

  • I have searched the issue tracker for a bug report that matches the one I want to file, without success.

Trilium Version

latest

What operating system are you using?

Other Linux

What is your setup?

Local (no sync)

Operating System Version

Ubuntu live server 20.10

Expected Behavior

To have data in data-Folder.

version: '2.1'
services:
  trilium:
    build:
      context: .
    image: zadam/trilium
    restart: always
    environment:
      - TRILIUM_DATA_DIR=/data
    ports:
      - "8080:8080"
    volumes:
      - trilium:/data

volumes:
  trilium:

Neither - TRILIUM_DATA_DIR=/data nor volumes: - trilium:/data does anything meaningful. The data folder / volume is empty and recreated every time the docker image is recreated -> It stores the data inside the container itself (probably)

Actual Behavior

Empty data folder, data is recreated everytime docker image is recreated -> data is probably stored inside the docker container itself.

@Unrepentant-Atheist
Copy link
Author

Unrepentant-Atheist commented Oct 16, 2021

Solution: chown -R 1000:1000 the trilium volume.

@zadam
Copy link
Owner

zadam commented Oct 16, 2021

Hi, I'm not sure what exactly needs to be fixed. Would you mind creating a PR?

Thanks.

@Unrepentant-Atheist
Copy link
Author

Unrepentant-Atheist commented Oct 16, 2021

No idea, sorry. I'm just reporting a bug. For the data volume to actually work and have any data inside it I have to chown -R 1000:1000 the trilium volume manually, before that it was root:root. Before one does that, one will get access permission errors like https://hastebin.com/ukegeguluy.typescript . I suspect it's got to do with step 4 : https://i.imgur.com/Nd8D4w5.png . I'm no expert tho.

@zadam
Copy link
Owner

zadam commented Oct 16, 2021

I see. This file was contributed externally as a sort of example, maybe it's missing e.g. the exact directory mapping which needs to be filled by the end-user.

If the file is more confusing than helpful I might just delete it.

@mariushosting
Copy link

You can't save right now any file inside the mapped folder "trilium" /data. There is a bug somewhere.

@wwwald
Copy link

wwwald commented Oct 19, 2021

I'm syncing my desktop Trilium instance with a Docker-based Trilium instance on a remote server. The specified volume (~/trilium-data in the configuration below) actually does contain the Trilium SQLite database, and it gets modified on every sync so it's definitely persisting the Trilium DB in there.

My docker-compose config:

trilium:
    image: zadam/trilium:0.48.1-beta
    ports:
        - "8080:8080"
    volumes:
        - ~/trilium-data:/home/node/trilium-data
    networks:
        - web
    ...

Are you sure that the directories & permissions specified are valid in your specific setup?

@Fofuxo
Copy link

Fofuxo commented Oct 24, 2021

i have the same issue, when creating a new install on docker, logs say it has no write perms.. chown -R 1000:1000 the trilium volume. did the trick

@Mist-Hunter
Copy link

Mist-Hunter commented Sep 28, 2023

Thank you for Trilium, it is one the best note taking apps I have ever seen, really awesome.

I just want to add in here, that TRILIUM_DATA_DIR as seen in the docker-compose.yml doesn't seem to be supported by the script logic anywhere outside of /home/node

Looking at start-docker.sh

#!/bin/sh

[[ ! -z "${USER_UID}" ]] && usermod -u ${USER_UID} node || echo "No USER_UID specified, leaving 1000"
[[ ! -z "${USER_GID}" ]] && groupmod -g ${USER_GID} node || echo "No USER_GID specified, leaving 1000"

chown -R node:node /home/node
exec su-exec node node ./src/www

The only chown in the containers code that doesn't run after exec su-exec node node is chown -R node:node /home/node

In my mind chown -R node:node /home/node should be changed to chown -R node:node $TRILIUM_DATA_DIR or another line should be added to include chown -R node:node $TRILIUM_DATA_DIR.

I believe what is happening in number of open issues, is mkdir is correctly getting called to create (as an example) $TRILIUM_DATA_DIR/logs but it fails because the whole container is running under the root user and the $TRILIUM_DATA_DIR is mounted with root permissions, but mkdir and other commands are running under node at 1000 or $USER_UID / $USER_GID.

@zadam
Copy link
Owner

zadam commented Oct 2, 2023

In my mind chown -R node:node /home/node should be changed to chown -R node:node $TRILIUM_DATA_DIR or another line should be added to include chown -R node:node $TRILIUM_DATA_DIR.

This shouldn't matter - $TRILIUM_DATA_DIR is actually empty in the docker container and the whole /home/node ownership is being changed to node user. trilium-data is then created within /home/node, all with node user ownership ...

The container is starting as root user, but changing immediately to run under node user ...

@Mist-Hunter
Copy link

Mist-Hunter commented Oct 2, 2023

Thanks for the quick reply, I thought that $TRILIUM_DATA_DIR was able to point anywhere (as am example, I was using /data) and mkdir seemed to be choking on creating a / path. I must have been looking at it wrong.

The compose below is an example of what I (and I think a few others) we trying to do with $TRILIUM_DATA_DIR.

version: '2.1'
services:
  trilium:
    image: zadam/trilium
    restart: always
    environment:
      - TRILIUM_DATA_DIR=/data
    ports:
      - "8080:8080"
    volumes:
      - trilium:/data

volumes:
  trilium:

edit: I just realized this example was literally in the first post. doh!

zadam added a commit that referenced this issue Oct 3, 2023
@zadam
Copy link
Owner

zadam commented Oct 3, 2023

So I tested the docker-compose and I didn't figure out where it actually stores the data.

I changed the config so that it by default uses ~/trilium-data on the host with the possibility of overriding this.

@Mist-Hunter
Copy link

Thanks so much, was plenty easy to work around, but might help some people. Also thanks again for the awesome app. I've looked for years for replacement to OneNote this app is it.

@tidalvirus
Copy link

tidalvirus commented Nov 4, 2023

I realise this issue is now fixed, as per the PR above, but I saw this bug mentioned in the release notes for 0.61.12 and got puzzled - the following docker-compose file snippet has worked for me since I started using Trilium - around June 2023, I think.

    image: zadam/trilium:latest
    container_name: tr-sr
    restart: unless-stopped
    environment:
      - TRILIUM_DATA_DIR=/home/node/trilium-data
    volumes:
      - /mnt/containers/trilium/sr-data:/home/node/trilium-data

And the directory structure that created:

sr@brutish:/mnt/containers/trilium$ ls -l
total 9
drwxr-xr-x 5 sr sr 10 Sep  1 13:39 sr-data
sr@brutish:/mnt/containers/trilium$ ls -l sr-data/
total 10796
drwx------ 2 sr sr       6 Nov  4 02:42 backup
-rw-r--r-- 1 sr sr    1609 Jun 18 14:41 config.ini
-rw-r--r-- 1 sr sr 6430720 Nov  1 15:38 document.db
-rw-r--r-- 1 sr sr   32768 Nov  4 18:48 document.db-shm
-rw-r--r-- 1 sr sr 4185952 Nov  4 18:48 document.db-wal
drwx------ 2 sr sr     142 Nov  4 11:00 log
drwxr-xr-x 2 sr sr       6 Nov  4 18:48 sessions
-rw-r--r-- 1 sr sr      64 Jun 18 14:41 session_secret.txt

Is this not the right way to be setting this up?

PS. I have the container named the way it is, as I plan to set up more containers for others in the family - this is the only way I can think of to do it easily, as trilium doesn't do users :)

@PretzelVector
Copy link

PretzelVector commented Nov 10, 2023

Is this not the right way to be setting this up?

I think you're good.

I came here through the same path of "I use docker compose and based it off the example, do I need to fix something?". The default configuration used to put the trilium data into a volume. Now, if TRILIUM_DATA_DIR is set in your .env or otherwise in your environment, it will place the trilium data onto the host in the path specified by TRILIUM_DATA_DIR.

If you have a working configuration, no action is required.

PS. I have the container named the way it is, as I plan to set up more containers for others in the family - this is the only way I can think of to do it easily, as trilium doesn't do users :)

FWIW, this is my setup: traefik routing to several trilium instances by path e.g. https://domain.tld/user1/

  trilium-user1:
    image: zadam/trilium
    container_name: trilium-user1
    restart: unless-stopped
    networks:
      - traefik
    labels:
      - 'traefik.enable=true'
      - 'traefik.http.routers.trilium-user1.rule=Host(`${TRILIUM_HOST}`) && PathPrefix(`/user1/`)'
      - 'traefik.http.routers.trilium-user1.entryPoints=https'
      - 'traefik.http.routers.trilium-user1.tls=true'
      - 'traefik.http.routers.trilium-user1.tls.certresolver=trilium'
      - 'traefik.http.middlewares.trilium-user1-strip.stripprefix.prefixes=/user1'
      - 'traefik.http.routers.trilium-user1.middlewares=trilium-user1-strip@docker'
      - 'traefik.http.services.trilium-user1.loadbalancer.server.port=8080'
    environment:
      - TRILIUM_DATA_DIR=/home/node/trilium-data
    volumes:
      - trilium-user1:/home/node/trilium-data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants