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

Precreate and chown snapshots and storage dirs #2921

Merged
merged 1 commit into from Nov 3, 2023

Conversation

ilkecan
Copy link
Contributor

@ilkecan ilkecan commented Nov 2, 2023

... in unprivileged mode to avoid Docker named volumes being owned by the root user.

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Currently, with this docker-compose.yaml file:

---
version: "3.8"

name: test

services:
  qdrant:
    image: qdrant/qdrant:v1.6.1-unprivileged
    volumes:
      - qdrant:/qdrant/storage/

volumes:
  qdrant:

docker compose up fails:

...
test-qdrant-1  | 2023-11-02T20:24:57.189168Z  INFO storage::content_manager::consensus::persistent: Initializing new raft state at ./storage/raft_state.json
test-qdrant-1  | Error: Service internal error: Failed to write file: Permission denied (os error 13) at path "/qdrant/./storage/.atomicwriteZEuaWn"
test-qdrant-1 exited with code 1

If we change the container command to ls -al we see that the target of the Docker named volume is owned by the root user:

Attaching to test-qdrant-1
test-qdrant-1  | total 57248
test-qdrant-1  | drwxr-xr-x 1 qdrant qdrant     4096 Nov  2 20:26 .
test-qdrant-1  | drwxr-xr-x 1 root   root       4096 Nov  2 20:26 ..
test-qdrant-1  | drwxr-xr-x 1 qdrant qdrant     4096 Oct  9 09:45 config
test-qdrant-1  | -rwxrwxr-x 1 qdrant qdrant     1840 Sep  6 22:21 entrypoint.sh
test-qdrant-1  | -rwxr-xr-x 1 qdrant qdrant 58590208 Oct 11 15:39 qdrant
test-qdrant-1  | drwxr-xr-x 1 qdrant qdrant     4096 Oct 11 15:39 static
test-qdrant-1  | drwxr-xr-x 2 root   root       4096 Nov  2 20:24 storage
test-qdrant-1 exited with code 0

A similar error is received when the volume targets snapshots directory instead.

After some research, it seems the only way to fix this is to run chown inside the container. It works even if we run chown before the volume is mounted. Currently chown is already run in here:

chown -R "$USER_ID:$USER_ID" "$APP"; \

But since snapshots and storage directories don't exist at that point, they are not currently affected by it. The solution is to precreate those directories before that line, and this PR does that.

@ilkecan ilkecan force-pushed the docker-chown-storage-and-snapshots branch from d8e7005 to 1a443dc Compare November 2, 2023 23:43
Dockerfile Outdated Show resolved Hide resolved
... in unprivileged mode to avoid Docker named volumes being owned by
the root user.
@ilkecan ilkecan force-pushed the docker-chown-storage-and-snapshots branch from 1a443dc to ac37faf Compare November 3, 2023 10:19
Copy link
Member

@generall generall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those directories are not absolute and can depend on the configuration, I am afraid we can't just hard-code them in docker

@timvisee
Copy link
Member

timvisee commented Nov 3, 2023

Those directories are not absolute and can depend on the configuration, I am afraid we can't just hard-code them in docker

Even if the user would define custom ones, I don't think it would hurt if these two are created by default in the image.

@bashofmann
Copy link
Contributor

The root issue is that docker compose does not allow you to configure permissions when mounting a named volume. Instead it inherits the permissions of the existing directory, or mounts it as root if no directory exists.

There is a issue from 2016 about this docker/compose#3270.

I guess it does not hurt to have the default locations present in the image. Most users won't change these, and if they do, and run in docker-compose, they need to work around this somehow. For example by building their own image or just not using docker-compose.

@generall generall merged commit 8bec3bc into qdrant:dev Nov 3, 2023
18 checks passed
generall pushed a commit that referenced this pull request Dec 6, 2023
... in unprivileged mode to avoid Docker named volumes being owned by
the root user.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants