Add mounted volume from non-root user to docker container

86 Views Asked by At

I have a Linux VM provided to me on which network drives has already been mounted, to access it there is an extra non-root user "user1".

The id of this user is:

uid=4040 (user1) gid=110 (lxd) groups=110 (lxd)

Since I didn't set it up and the colleague responsible is on vacation, I have no idea how he connected it. He just said that he uses the NIS to connect it. However, I did not find the user1 in the /etc/passwd file.

Access on the VM from this user works.


Problem:

I would now like to start a Docker container which can also access it. I have used the following test setup for this:

compose.yml:

version: '3'
services:
  test:
    build: .
    user: 4040:110
    volumes:
      - type: bind 
        source: /nfs1/transfer
        target: /mnt/transfer 
    tty: true 

Dockerfile:

FROM ubuntu:22.04

# Test to add User
RUN adduser -uid 4040 -gid 110 user1

The Container starts without an error message. However, as soon as I want to display the contents of /mnt/transfer in the container, it is empty.

I can create a file in the directory that is still there when I restart the container, but it is not in /nfs1/transfer of the VM.

Is that even possible or can Docker not integrate such mounts at all?


Things I have tested:

Dockerfile:

  • without adduser
  • with addgroup -gid 110 lxd
  • with mkdir /mnt/transfer && chmod a+rwx /mnt/transfer

compose.yml

  • without user: 4040:110
0

There are 0 best solutions below