Skip to content

Conversation

mihaon
Copy link
Contributor

@mihaon mihaon commented Aug 10, 2025

The https://directus.io/docs/getting-started/create-a-project contains a docker-compose.yml which will cause a permissions error when trying to upload files via the admin panel just after first start. It happens because docker "bind mount" host directory (in contrast to named volumes) is not initialized with owner/permissions taken from inside the container directory.

But since from Docker Compose 2.30 it became possible to use a post-start hook to fix this problem - https://docs.docker.com/compose/how-tos/lifecycle/#post-start-hooks.

So quick fix for .yml might be:

services:
    directus:
        # ...
        volumes:
            - ./database:/directus/database
            - ./uploads:/directus/uploads
            - ./extensions:/directus/extensions
        post_start:
            - command: chown node:node /directus/database /directus/uploads /directus/extensions
              user: root
        # ...

P.S.: this can also be fixed by adding chown to the CMD in the Dockerfile (like postgres docker image does)

Fix owner/permissions problem
@mihaon mihaon requested a review from a team as a code owner August 10, 2025 14:32
Copy link

vercel bot commented Aug 10, 2025

@mihaon is attempting to deploy a commit to the Directus Team on Vercel.

A member of the Team first needs to authorize it.

@Nitwel
Copy link
Member

Nitwel commented Oct 16, 2025

Is this a specific problem when running the compose file on linux cause on Windows I'm not running into such problems?

@mihaon
Copy link
Contributor Author

mihaon commented Oct 19, 2025

I don't know about Windows. Did you try to docker compose up without first creating the uploads directory?

In Linux I get:

$ ls -lh
-rw-rw-r--  1 m    m     533 Oct 19 16:08 docker-compose.yml

$ docker compose up

$ ls -lh
drwxr-xr-x  2 root root 4.0K Oct 19 16:09 database
drwxr-xr-x  2 root root 4.0K Oct 19 16:09 extensions
drwxr-xr-x  2 root root 4.0K Oct 19 16:09 uploads
-rw-rw-r--  1 m    m     533 Oct 19 16:09 docker-compose.yml

So, the node user from inside the container can't access to the root owned directories.

@mihaon
Copy link
Contributor Author

mihaon commented Oct 19, 2025

Postgres docker image contains another workaround to prevent same issue:
https://github.com/docker-library/postgres/blob/22ca5c8d8e4b37bece4d38dbce1a060583b5308a/18/trixie/docker-entrypoint.sh#L58

Workaround in the Dockerfile (like in the Postgres) is better then post_start command in the compose file because it doesn't complicate the compose file.

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.

2 participants