Skip to content

Allow the UID/GID to be changed #359

Description

@derekoharrow

I have a CIFS/SMB volume mounted on my docker host, accessed by many of my containers. For all the other containers, I can specify a UID/GID in the docker-compose file so that they have read/write access to this volume.
How do you specify the UID/GID for NextCloud? As it stands, it can read the volume but doesn't have write access.
Thanks

Activity

  1. derekoharrow commented on Jun 6, 2018

    @derekoharrow
    Author

    I see in the instructions that you can do the following:
    docker exec --user www-data CONTAINER_ID php occ
    But how do you specify the user in the docker-compose.yml file?

  2. changed the title [-]How to change UID/GID in NextCloud container?[/-] [+]Allow the UID/GID to be changed[/+] on Jun 7, 2018
  3. tilosp commented on Jun 7, 2018

    @tilosp
    Member

    There is currently no way to change the UID and GID. I think this is supported by the parent image. But the entrypoint script does not properly support it.

  4. itay-grudev commented on Jul 11, 2018

    @itay-grudev
  5. tilosp commented on Feb 27, 2019

    @tilosp
    Member

    this should be possible. this works for me:
    docker run --user 1234 -p 8080:80 --sysctl net.ipv4.ip_unprivileged_port_start=0 nextcloud

  6. caillou commented on Mar 24, 2019

    @caillou

    @tilosp Thanks for your comment. Unfortunately I don't seem able to reproduce this.

    My host system has a user with the ID 1000. When I run the following command, the files created in the /storage/docker/nextcloud/config belong to www-data root.

    docker run \
    -d \
    --user 1000 \
    --name=nextcloud \
    --network=private-network \
    -e NEXTCLOUD_DATA_DIR=/data \
    -v /storage/docker/nextcloud/config:/var/www/html \
    -v /storage/docker/nextcloud/data:/data \
    nextcloud
    

    Are you sure this worked on your end?

  7. marianrh commented on Mar 29, 2019

    @marianrh

    @caillou I'm using the suggestion by @tilosp via docker-compose. I can confirm that files uploaded to Nextcloud get the UID/GID as set in docker-compose.yaml. However, I converted an existing installation to this and didn't try upgrading the container to a newer version yet, so I cannot say anything about what permissions Nextcloud's own files will receive then.

  8. ashtonian commented on Apr 8, 2019

    @ashtonian

    when I use user: "${uid}:${guid}" field in a compose file with docker swarm (sudo docker stack deploy --compose-file...) I get permissions errors:

    Initializing nextcloud 15.0.6.1 ...
    rsync: mkstemp "/var/www/html/config/.htaccess.oCsWlP" failed: Permission denied (13)
    rsync: mkstemp "/var/www/html/config/.apache-pretty-urls.config.php.1OjgZw" failed: Permission denied (13)
    rsync: mkstemp "/var/www/html/config/.apcu.config.php.qFhACe" failed: Permission denied (13)
    rsync: mkstemp "/var/www/html/config/.apps.config.php.lijUfW" failed: Permission denied (13)
    rsync: mkstemp "/var/www/html/config/.autoconfig.php.EgpeTD" failed: Permission denied (13)
    rsync: mkstemp "/var/www/html/config/.config.sample.php.toAywl" failed: Permission denied (13)
    rsync: mkstemp "/var/www/html/config/.redis.config.php.ahOV92" failed: Permission denied (13)
    rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1196) [sender=3.1.2]
    

    running image: nextcloud:apache container as well as a separate one with the .cron entry-point, volumes are just named volumes created on up.

  9. mabushey commented on Apr 9, 2019

    @mabushey

    @marianrh

    I can confirm that files uploaded to Nextcloud get the UID/GID as set in docker-compose.yaml.

    Can you tell me how you set the UID/GID in docker-compose?

  10. marianrh commented on Apr 9, 2019

    @marianrh

    @mabushey Sure, this is the docker-compose file I'm using:

    version: "3.3"
    services:
      nextcloud:
        image: nextcloud:15.0.6-apache
        dns:
          - <...>
          - <...>
        user: 5003:5003
        sysctls:
          - net.ipv4.ip_unprivileged_port_start=0 # Allow an unprivileged user to listen on any port (https://github.com/nextcloud/docker/issues/359)
        ports:
          - 8092:80
        volumes:
          - /applications/nextcloud:/var/www/html
    
    networks:
      default:
        driver: bridge
        ipam:
          driver: default
          config:
          - subnet: <...>
    

    Of course, the directory on the host system has to have the proper owner set.

  11. mabushey commented on Apr 9, 2019

    @mabushey

    Thanks @marianrh. I added this to the nextcloud config:

        user: 1000:1000
        sysctls:
          - net.ipv4.ip_unprivileged_port_start=0
    

    (BTW the comment on the sysctls entry just refers to this thread)
    Removing the config directory and running docker-compose up -d results in a config dir (mapped - "/home/michael/docker/nextcloud:/var/www/html") that's root:root instead of www-data:root. I'm looking for michael:michael (1000:1000). I'm running MySQL outside of docker on the same box with the jwilder & lets encrypt companion Nginx proxy.

    Does the dns / networks have some part in this?

  12. mabushey commented on Apr 10, 2019

    @mabushey

    I was able to set mapall=michael to the ZFS share property on the FreeBSD NFS server and it seems to be working just fine with Nextcloud running as www-data.

  13. alesnav commented on Apr 17, 2019

    @alesnav

    Hi there!

    For those who are using Swarm like me, sysctls option is not supported... Keeping in mind that the only thing that crashes when starting up using another username is apache2 process, I've mapped the following volumes:

        volumes:
        - nextcloud_apache_ports:/etc/apache2/ports.conf
        - nextcloud_apache_default:/etc/apache2/sites-enabled/000-default.conf
    

    And, of course, local files have been changed to use port 20080 instead of port 80.

  14. 12 remaining items

  15. apjyotirmay commented on Jun 13, 2022

    @apjyotirmay

    I had to build from the official image to be able to change the UID and GID. My normal user's id is 1000, and this is what my Dockerfile looks like

    FROM nextcloud:23.0.5-fpm-alpine
    RUN apk --no-cache add shadow && \
        groupmod --gid 1001 www-data && \
        usermod --uid 1000 www-data

    After that I call this file to build my image:

    app:
        build:
            context: ./
            dockerfile: Dockerfile
        restart: always

    I hope it helps someone :)

  16. added 2 commits that reference this issue on Sep 1, 2022
    31bfade
    883c3b1
  17. added a commit that references this issue on Sep 6, 2022
    19256cd
  18. added a commit that references this issue on May 10, 2024
    96124b4
  19. QuinnBast commented on Oct 29, 2025

    @QuinnBast

    It's insane that this has been closed and has not been addressed after 6 years. Setting the user only when you shell or via docker user is not enough of a solution. We need to be able to set the user id. Most other apps support UID and GID for setting the user and group ID.

  20. perahoky commented on Feb 3, 2026

    @perahoky

    Hello,

    i switched to linuxservers/nextcloud image to get uid/gid support. I'm running nextcloud in a docker container on a synology nas where uid/gid on the host are different from the IDs in a container. This results in permissions conflicts, not just on external storage but also on config files and so on. Linuxservers Docker Image Provider solves this problem.

  21. joshtrichards commented on Feb 3, 2026

    @joshtrichards
    Member

    Setting the user only when you shell or via docker user is not enough of a solution. We need to be able to set the user id.

    The user parameter is not just for the command-line. It is what you specify in Compose too.

    Most other apps support UID and GID for setting the user and group ID.

    Those apps added support in that way before user was the convention. Even those are switching to user (see the box at the top of this page):

    https://docs.linuxserver.io/general/understanding-puid-and-pgid/

    Linuxservers Docker Image Provider solves this problem.

    Can you elaborate what you tried with the image here that didn't work?

    This is well supported.

    As a run command:

    docker run -d \
      --name nextcloud \
      --user 1000:1000 \
      -p 8080:80 \
      -v /path/to/data:/var/www/html/data \
      nextcloud
    

    As a Compose file:

    services:
      nextcloud:
        image: nextcloud
        container_name: nextcloud
        user: "1000:1000"
        restart: always
        ports:
          - "8080:80"
        volumes:
          - /path/to/data:/var/www/html/data
    
  22. sliekens commented on Apr 24, 2026

    @sliekens

    @joshtrichards Thanks for confirming user: is supported. It works in your example, but fails when REDIS_HOST is set. The entrypoint tries to write redis-session.ini to /usr/local/etc/php/conf.d/, which is drwxr-xr-x root root — the non-root user can't create files there.

    Minimal repro:

    services:
      nextcloud:
        image: nextcloud:32.0.8-apache
        user: "1000:1000"
        environment:
          - NEXTCLOUD_ADMIN_USER=admin
          - NEXTCLOUD_ADMIN_PASSWORD=admin
          - REDIS_HOST=redis
        volumes:
          - ./data:/var/www/html/data
    
      redis:
        image: valkey/valkey:9

    Error on startup:

    => Configuring PHP session handler...
    ==> Using Redis as PHP session handler...
    /entrypoint.sh: 121: cannot create /usr/local/etc/php/conf.d/redis-session.ini: Permission denied
    

    Is there a supported way to use user: together with Redis?

  23. joshtrichards commented on Apr 25, 2026

    @joshtrichards
    Member

    @sliekens Known issue (#763). There are numerous solutions, but one I am exploring for the image itself is in #2550. No promises it'll get merged, but testing feedback is appreciated and would help move it along.

  24. sliekens commented on Apr 25, 2026

    @sliekens

    Thanks, that issue didn't come up in my search. I can test your solution if there is a prebuilt image available, or if it's easy to build one myself. @joshtrichards

  25. vincentkoevoets commented on Jun 17, 2026

    @vincentkoevoets

    I'm more worried about other things that might be breaking in the background when using user: 1000:1000 (or any other uid and gid). We can just not use redis and the container will start seemingly fine, but will we run into trouble somewhere later in the process?

    Edit
    One error that might prove my point (from the docker logs):

    nextcloud_new  | Fontconfig error: No writable cache directories
    nextcloud_new  | Fontconfig error: No writable cache directories
    nextcloud_new  | Fontconfig error: No writable cache directories
    nextcloud_new  | Fontconfig error: No writable cache directories
    
  26. QuinnBast commented on Jun 22, 2026

    @QuinnBast

    I will mention, that using the built-in docker flags for user are not possible in Kubernetes without setting a custom security context, but in certain kubernetes environments, it might not be possible to set a security context, while setting ENV is possible.

  27. especially-relative commented on Jun 22, 2026

    @especially-relative

    I will mention, that using the built-in docker flags for user are not possible in Kubernetes without setting a custom security context, but in certain kubernetes environments, it might not be possible to set a security context, while setting ENV is possible.

    Right but in that case the container would have to start as root and use the uuid/guid env vars to drop to that user in the entrypoint script with is not good practice at all

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions