Skip to content

Use named volumes for mounting single files #1486

Description

@adria-boada

The Docker-compose documentation shows how it is possible to create a named bind mount. It should be mapped to a specific host path.

Named volumes specification works fine for directories, but they do not work for mounting single files. Podman returns an error. I am not sure if the error comes from Podman or Podman-compose.

Maybe I have poorly configured the named volume (see the example).

2c880aa9dd451f26554719bc295b9f691b1046022eb04f79c7591801a88eb593
[SERVICE] | Error: unable to start container 2c880aa9dd451f26554719bc295b9f691b1046022eb04f79c7591801a88eb593: mounting volume VOLUME-NAME for container 2c880aa9dd451f26554719bc295b9f691b1046022eb04f79c7591801a88eb593: mount: /home/USERNAME/.local/share/containers/storage/volumes/VOLUME-NAME/_data: wrong fs type, bad option, bad superblock on VOLUME-SOURCE, missing codepage or helper program, or other error.
[SERVICE] | dmesg(1) may have more information after failed mount system call.
[SERVICE] |

Example:

# Set up a tmp file.
echo "hello world" > /tmp/test-file-source
# docker-compose.yml
services:
  # This service always work, for directories and files.
  test_not_named:
    image: alpine
    volumes:
      - type: bind
        source: /tmp/test-file-source
        target: /tmp/test-file-target
    command: [ "cat", "/tmp/test-file-target" ]

  # This service returns an error for files, only works with directories.
  test_named:
    image: alpine
    volumes:
      - test_named_volume:/tmp/test-file-target
    command: [ "cat", "/tmp/test-file-target" ]
volumes:
  test_named_volume:
    driver: local
    driver_opts:
      type: bind
      device: "/tmp/test-file-target"
      o: "bind"
$ podman compose version
podman-compose version 1.6.0
podman version 5.8.2

Describe the solution you'd like

Possibility for named volumes to include named mounted files.

Describe alternatives you've considered

The first example works OK.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions