Problem with named volume in docker-compose

I’m having a problem getting a named volume to work locally in docker-compose. Here’s the docker-compose.yml I’m using:

---
version: "2.1"
services:
  my-service:
    image: alpine
    volumes:
      - alerts-volume:/var/folders
volumes:
  alerts-volume:
    #driver: local
    driver_opts:
      type: none
      o: bind
      device: /var/folders

When I run docker-compose up on that, I get the following error:

Creating network "steve_default" with the default driver
Creating volume "steve_alerts-volume" with default driver
Creating steve_my-service_1 ... error
ERROR: for steve_my-service_1  Cannot start service my-service: error while mounting volume '/var/lib/docker/volumes/steve_alerts-volume/_data': failed to mount local volume: mount /var/folders:/var/lib/docker/volumes/steve_alerts-volume/_data, flags: 0x1000: no such file or directory

It goes away when I un-comment the "driver: local" line. But that should be the default driver for volumes, so I don’t understand why that works. I’m using Docker version 19.03.13-beta2, build ff3fbc9d55 on Mac OS 10.14.6 (Mojave).

1 Like

The claim Docker beeing easy and reliable to use is somehow only true on Linux systems…

Since Docker for Mac/Windows rely on a linux VM to run docker, the local driver is local to the vm. If you bind a host folder, it will be local to the vm as well. Though, you could use the local driver to mount NFS remote shares. Docker will mount the NFS share whenever the volume is used by a container and unmounted when the container stops.

Since you are on OSX, enabling NFS shares should be no challenge.

I don’t follow your point about mounting an NFS directory. The problem I’m seeing happens with mounting any directory under /var; I only used /var/folders as an example.

To ask a different way: why do I need to specify driver: local for the volume? What other value does it have?

Thanks for this post! I just had the opposite issue and found the solution thanks to your issue.

docker run could mount the volume just fine, but docker compose dailed with “no such file or directory”. Explicitly specifying the driver: local in the docker-compose.yaml makes it work.

Windows 11, using WSL2.