Docker Community Forums

Share and learn in the Docker community.

Error while mounting volume with options: type='nfs'


(Ealebed) #1

Hi all!
I have a problem with mounting remote volume via nfs

OS Version/build: macOs High Sierra 10.13.2 (17C88)
App version: Version 17.12.0-ce-rc4-mac44 (21438) Channel: edge f23de3ecc6
Steps to reproduce:

I start containers using docker-compose up -d and my docker-compose.yml looks like this:

version: '3'
services:
### Redis 
  redis:
    container_name: redis
    image: redis:4.0-alpine
    command:
      - 'redis-server'
      - '--loglevel ${REDIS_LOGLEVEL:-warning}'
      - '--databases 2'
      - '--save 300 1'
      - '--save 60 1000'
      - '--maxmemory ${REDIS_MAXMEM:-50mb}'
      - '--maxmemory-policy ${REDIS_POLICY:-noeviction}'
      - '--requirepass ${REDIS_PASS}'
    volumes:
      - redis:/data
    ports:
      - "6379:6379"
    networks:
      default:
        ipv4_address: 172.25.0.11
### Memcached 
  memcached:
    container_name: memcached
    image: memcached:1.5-alpine
    volumes:
      - memcached:/var/lib/memcached
    ports:
      - "11211:11211"
### Dynamicus 
  dynamicus:
    container_name: dynamicus
    image: registry.gitlab.lc:5000/develop/ed/stv2-ed-sq
    volumes:
      - static:/var/www/static
    ports:
      - "8888:8888"
    networks:
      default:
        ipv4_address: 172.25.0.12
### Volumes Setup
volumes:
  memcached:
    driver: "local"
  redis:
    driver: "local"
  static:
    driver: "local"
    driver_opts:
      type: nfs
      o: "addr=192.168.0.21,rw"
      device: ":/srv/static"
networks:
  default:
    driver: bridge
    ipam:
      config:
      - subnet: 172.25.0.0/24

When I run docker-compose up -d in console I see:

docker-compose up -d
Creating network "docker_default" with driver "bridge"
Creating dynamicus ... error
Creating volume "docker_memcached" with local driver
Creating volume "docker_redis" with local driver
Creating redis ...
Creating dynamicus ...
Creating redis ... done
Creating memcached ...
Creating memcached ... done

ERROR: for dynamicus  Cannot start service dynamicus: error while mounting volume '/var/lib/docker/volumes/docker_static/_data': error while mounting volume with options: type='nfs' device=':/srv/static' o='addr=192.168.0.21,rw': permission denied
ERROR: Encountered errors while bringing up the project.

When I add option vers=4 in docker-compose.yml like this:

volumes:
  static:
    driver: "local"
    driver_opts:
      type: nfs
      o: "addr=192.168.0.21,vers=4,rw"
      device: ":/srv/static"

I got another error message:

docker-compose up -d
Creating network "docker_default" with driver "bridge"
Creating volume "docker_static" with local driver
Creating volume "docker_memcached" with local driver
Creating volume "docker_redis" with local driver
Creating redis ... done
Creating dynamicus ...
Creating dynamicus ... error
Creating memcached ...

ERROR: for dynamicus  Cannot start service dynamicus: error while mounting volume '/var/lib/docker/volumes/docker_static/_data': error while mounting volume with options: type='nfs' device=':/srv/static' o='addr=192.168.0.21,vers=4,rw': operation not permitted
ERROR: Encountered errors while bringing up the project.

On my nfs-server (192.168.0.21) in /etc/exports write this line:

/srv/static *(rw,sync,no_subtree_check)

Nfs-server is accessible from my mac:

$ showmount -e 192.168.0.21
Exports list on 192.168.0.21:
/srv/static                         *

In /etc/nfs.conf on my mac I have this:

$ cat /etc/nfs.conf
#
# nfs.conf: the NFS configuration file
#
nfs.server.mount.require_resv_port = 0

I can mount nfs resource to my maс using command:

sudo mount -t nfs -o resvport,rw 192.168.0.21:/srv/static /private/srv/static

Adding option resvport to my docker-compose.yml didn’t help:

volumes:
  static:
    driver: "local"
    driver_opts:
      type: nfs
      o: "addr=192.168.0.21,resvport,vers=4,rw"
      device: ":/srv/static"

In console:

docker-compose up -d
Creating network "docker_default" with driver "bridge"
Creating volume "docker_static" with local driver
Creating volume "docker_memcached" with local driver
Creating volume "docker_redis" with local driver
Creating dynamicus ... error
Creating redis ... done
Creating redis ...

ERROR: for dynamicus  Cannot start service dynamicus: error while mounting volume '/var/lib/docker/volumes/docker_static/_data': error while mounting volume with options: type='nfs' device=':/srv/static' o='addr=192.168.0.21,resvport,vers=4,rw': operation not permitted
ERROR: Encountered errors while bringing up the project.

Can anybody help with this?


(Scarlson) #2

@ealebed Did you ever figure this out? I am facing a similar issue. I’m not certain but the permission denied may need the privileged: true flag set, although I am unsure how to do this since privileged is a runtime command…


(Ealebed) #3

Hi!
No, I haven’t solve this yet…
Possibly, I shall move my nfs storage to S3 / Google Cloud and change all links to “static” volume in my code ((((


(Scarlson) #4

Albiet my problem was much simpler than yours I got it to work by How to mount nfs drive in container: simplest way


(Dansmall) #5

You almost had it! It looks like OSX defaults to non-privileged ports, but your NFS server doesn’t allow it. The easiest thing I’ve found is the explicit use of the insecure option. For example, /srv/static *(rw,sync,no_subtree_check,insecure).

TL;DR:
To help troubleshoot this, I just did a tail -f /var/log/syslog and try to mount the export via the docker workflow. It gave me an error like:
Jun 12 16:38:26 <server_name> rpc.mountd[12274]: refused mount request from <ip_addr> for <export_path>: illegal port 53032

The important bit being the illegal port.


(Hzeineddine) #6

Finally it works ! :grinning:
Do you have any idea how can we do this without this dirty “insecure” workaround ?