[Mac M1] NFS connection refused

Hello everyone,

I’m trying to work with NFS volume but I’m getting the following error:

renansantos@Supports-MacBook-Pro myrepo % docker-compose up
Creating my-container ... error

ERROR: for my-container  Cannot create container for service my-container: failed to mount local volume: mount :/Users/renansantos/Git/myrepo/var/lib/docker/volumes/myrepo/_data, data: addr=127.0.0.1,nolock,hard,nointr,nfsvers=3: connection refused

ERROR: for my-container  Cannot create container for service my-container: failed to mount local volume: mount :/Users/renansantos/Git/myrepo/var/lib/docker/volumes/myrepo/_data, data: addr=127.0.0.1,nolock,hard,nointr,nfsvers=3: connection refused
ERROR: Encountered errors while bringing up the project.
renansantos@Supports-MacBook-Pro myrepo %

My docker-compose.yml

version: '3'

services:
  my-container:
    container_name: my-container
    image: node:16-alpine
    platform: linux/x86_64
    volumes:
      - "nfsmount:/usr/local/app"
    working_dir: /usr/local/app
    entrypoint: 'sh'
    command: '-c "yarn && yarn dev"'

volumes:
  nfsmount:
    driver: local
    driver_opts:
      type: nfs
      o: addr=localhost,rw,nolock,hard,nointr,nfsvers=3
      device: ":${PWD}"

Content from /etc/exports, my user id is 502.

/Users -alldirs -mapall=502:20 localhost

/etc/nfs.conf

nfs.server.mount.require_resv_port = 0

nfsd is running

renansantos@Supports-MacBook-Pro bin % nfsd status
nfsd service is enabled
nfsd is running (pid 2581, 8 threads)
renansantos@Supports-MacBook-Pro bin %

I’m on macOS Monterey 12.3(Chip Apple M1) using the last version from Docker Desktop, I tested changing the nfs version to 4 but it didn’t work.

Also, I’ve added full disk access for Docker and Docker-compose in security and privacy.

Do you have any idea how I can fix it?

Thanks!

It is a guess, because I don’t use NFS volumes often, especially not with “localhost” and I don’t remember how NFS volumes are mounted into a container, but you should not use “localhost” since even if your NFS server is on your MacOS locally, docker is running inside a virtual machine so it will not be able to see the server. You can try host.docker.internal or use the IP address of your machine.