'Docker Wordpress tar: <file> Cannot change ownership to uid 33, gid 33: Operation not permitted

I have created a docker-compose file for local development using Wordpress, and I've finally got NFS working (normal volume mount was too slow, because of Docker / Mac issues).

Except I'm running into a new issue, all files in the NFS share (which is the wp_content folder) give such error:

tar: ./wp-content/themes/twentynineteen/archive.php: 
Cannot change ownership to uid 33, gid 33: Operation not permitted

I've found this issue https://github.com/docker-library/wordpress/issues/137 in which they refer to https://github.com/docker-library/wordpress/pull/249, but I still can't get it working. Wondering if anyone can help me out, this is my docker-compose file:

version: '3.3'

services:
  wordpress:
    image: wordpress:latest
    ports:
      - "80:80"
    restart: always
    volumes:
      - nfsmount:/var/www/html/wp-content
      - ./.htaccess:/var/www/html/.htaccess:cached
      - ./wp-data/wp-config.php:/var/www/html/wp-config.php:cached
      - ./logs/debug.log:/var/www/html/wp-content/debug.log
    environment:
      APACHE_RUN_USER: www-data
      APACHE_RUN_GROUP: www-data

volumes:
  nfsmount:
    driver: local
    driver_opts:
      type: nfs
      o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
      device: ":/Users/myuser/Sites/dockertest/wp-data/wp-content" 


Solution 1:[1]

The error is reported by tar command that try to change owner.

In order to avoid tar to set owner you can set variable TAR_OPTIONS to --no-same-owner
From tar manual:

--no-same-owner
Extract files as yourself (default for ordinary users).

You can add this in your docker-compose file with :

  TAR_OPTIONS: --no-same-owner

Solution 2:[2]

The problem that you are having is that you are mounting a local volume with your user's permissions, and not www-data. As such, www-data is not able to change the permissions of files that your user owns. To fix it, you should be able to do chown 33:33 -R /Users/myuser/Sites/dockertest/wp-data/wp-content. Keep in mind that if you get and error something like Permissions denied, run the command with sudo.

Solution 3:[3]

First, you could try setting the additional volume option of nocopy to True.

If that doesn't work maybe you check the groups www-data is part of. I think in case you want to set the user and group to www-data, ensure www-data is part of the same group as the nfs shared folder.

Else it is preferred to use a local user and group that has access to the nfs file.

APACHE_RUN_USER  : local_user
APACHE_RUN_GROUP : local_group

Solution 4:[4]

Add this to services.wordpress.environment:

TAR_OPTIONS: "--owner=www-data"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 akrantz01
Solution 3 pappachino
Solution 4 Nabil Kadimi