windowsdockerdocker-compose

Docker Compose on Windows 11 bind mount error: "service volume xxx[0] is missing a mount target"


I am running Docker v25.0.3 via Docker Desktop on Windows 11. I cannot get my bind mount volume to work with Docker Compose.

My docker-compose.yaml looks like this:

version: '3'
services:
  oidc-server-mock:
    container_name: oidc-server-mock
    image: ghcr.io/soluto/oidc-server-mock:latest
    ports:
      - '8080:80'
    environment:
      ASPNETCORE_ENVIRONMENT: Development
      CLIENTS_CONFIGURATION_PATH: config/clients-config.json
    volumes:
      - type: bind
      - source: /mnt/c/Users/my/local/config/path
      - target: /config

It does work if, instead of using docker compose, I use docker run fom Powershell with the following parameters: --mount type=bind,source=C:\my\local\config\path,target=/config

But for some reason docker compose doesn't like my file.

What I have tried: I've tried different every imaginable path format suggested by online searches for my docker-compose.yml's -source parameter, both with and without double quotes surrounding the path. Furthermore, I cannot find anything online where this specific error message "missing a mount target" is mentioned verbatim.


Solution

  • Solution

    Your syntax is incorrect:

        volumes:
          - type: bind
          - source: /mnt/c/Users/my/local/config/path
          - target: /config
    

    This should instead be:

        volumes:
          - type: bind
            source: /mnt/c/Users/my/local/config/path
            target: /config
    

    or in short format:

        volumes:
          - /mnt/c/Users/my/local/config/path:/config
    

    Explanation

    - in yaml indicates a list element. What you are basically doing with your current config is that you define 3 different volumes: one with only type, another with only source and a third with only target. The error refers to the first ([0]) element on the list.

    The equivalent syntax error with docker run would be something like this:

    docker run --mount type=bind --mount source=C:\my\local\config\path --mount target=/config
    

    As a clearer example, if you would need a second volume, the correct syntax would be:

        volumes:
          - type: bind
            source: /mnt/c/Users/my/local/config/path
            target: /config
          - type: bind
            source: /foo
            target: /bar