permission denied issue when using mysql container and mounting remote volume

I want to setup a MySQL container and mount a remote volume with vieux/sshfs plugin but I got permission denied issue when I tried to access to the volume in the MySQL container.

I have tried to mount the volume with directory which owned by me (Allen, 1001:1001) on the remote server (mysshvolume), then I have full access to the volume inside MySQL container, however, when I tried to mount the remote directory owned by MySQL (111:113) (MySQL test volume), the volume can be mounted to MySQL container successfully but I don’t have any permission to read or write to the remote directory. I have tried chown in the container, –user 111:113 when docker run but both of the methods are not working.

[email protected]:/home/allen# docker volume inspect MySQL test
[
    {
        "CreatedAt": "0001-01-01T00:00:00Z",
        "Driver": "vieux/sshfs:latest",
        "Labels": {},
        "Mountpoint": "/mnt/volumes/95eae2d1ab60a27c3f7148411e113754",
        "Name": "mysqltest",
        "Options": {
            "password": "*********",
            "sshcmd": "[email protected]:/var/lib/mysql"
        },
        "Scope": "local"
    }
]




[email protected]:/home/allen# docker volume inspect mysshvolume
[
    {
        "CreatedAt": "0001-01-01T00:00:00Z",
        "Driver": "vieux/sshfs:latest",
        "Labels": {},
        "Mountpoint": "/mnt/volumes/f0fee43b051fc77a52b42930880959f6",
        "Name": "mysshvolume",
        "Options": {
            "password": "********",
            "sshcmd": "[email protected]:/home/allen"
        },
        "Scope": "local"
    }
]



[email protected]:/home/allen# docker run -it --name test -e 
MYSQL_ROOT_PASSWORD=123456 --privileged=true -v mysqltest:/world:z --user 
111:113 mysql /bin/bash
I have no [email protected]:/$ ls
bin  boot  dev  docker-entrypoint-initdb.d  entrypoint.sh  etc  home  lib  
lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var  
world
I have no [email protected]:/$ cd world
bash: cd: world: Permission denied
I have no [email protected]:/$ ls
bin  boot  dev  docker-entrypoint-initdb.d  entrypoint.sh  etc  home  lib  
lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var  
world
I have no [email protected]:/$ ls -l
ls: cannot access 'world': Permission denied
total 68
...
d?????????   ? ?    ?       ?            ? world


[email protected]r:/home/allen# docker run -it --name test -e 
MYSQL_ROOT_PASSWORD=123456 --privileged=true -v mysqltest:/world:z  mysql 
/bin/bash
[email protected]:/# ls
bin  boot  dev  docker-entrypoint-initdb.d  entrypoint.sh  etc  home  lib  
lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var  
world
[email protected]:/# ls -l
total 72
...
drwx------   1  111  113 4096 Sep 25 09:37 world
[email protected]:/# cd world
[email protected]:/world# ls
ls: reading directory '.': Permission denied

When I try docker run with –user 111:113 and check the ownership of world directory, it cannot be shown. If I do not define any user when setup the container with docker run, the ownership of the world directory is 111:113. But still, with both of the method, I don’t have permission to the world directory which is the remote volume owned by MySQL (111:113) on the remote server. I expect to acquire full access to world directory without chown at a remote server.

Source: StackOverflow