0

I want to mount NFS share for a Docker container.

I know it is possible since Docker 17.06, like described by ThiagoAlves in this answer.

docker run --mount \
  "src=$NFS_VOL_NAME,dst=$NFS_LOCAL_MNT,volume-opt=device=:$NFS_SHARE,\"volume-opt=o=addr=$NFS_SERVER,$NFS_OPTS\",type=volume,volume-driver=local,volume-opt=type=nfs" \
  busybox ls $NFS_LOCAL_MNT

But I want to do it using low-level Python API. There is a create_container function with a volumes parameter but I only found examples for a classic mount (local_folder:container_folder). Ex:

container_id = client.api.create_container(
    'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'],
    host_config=client.api.create_host_config(binds={
        '/home/user1/': {
            'bind': '/mnt/vol2',
            'mode': 'rw',
        },
        '/var/www': {
            'bind': '/mnt/vol1',
            'mode': 'ro',
        }
    })
)

How to call create_container or create_host_config to mount NFS shares?

Thanks!

  • From your link: `mounts (list) – Specification for mounts to be added to the container. More powerful alternative to binds. Each item in the list is expected to be a docker.types.Mount object.` and `class Mount(target, source, type='volume'...`. `like described by ThiagoAlves in this answer.` Like in docker documentation https://docs.docker.com/storage/volumes/#choose-the--v-or---mount-flag – KamilCuk Nov 11 '22 at 20:15

0 Answers0