podman-compose icon indicating copy to clipboard operation
podman-compose copied to clipboard

Mounting non-existing files with Podman Compose is not consistent with mounting them with Podman

Open jevooq opened this issue 1 year ago • 1 comments

Describe the bug

Mounting non-existing files with Podman Compose is not consistent with mounting them with Podman.

When Podman tries to mount a non-existing file it fails.

With Podman Compose it instead creates a directory with the name of the file and runs.

To Reproduce

Podman

podman run --rm -v ./no_file:/no_file hello-world

Error: lstat no_file: no such file or directory

podman run --rm --mount type=bind,source=./no_file,target=/no_file hello-world

Error: statfs /tmp/no_file: no such file or directory

Podman Compose

services:
  hello:
    image: hello-world
    volumes:
      - ./no_file:/no_file

podman-compose up

Creates a directory called no_file.

services:
  hello:
    image: hello-world
    volumes:
      - type: bind
        source: ./no_file
        target: /no_file

podman-compose up

Creates a directory called no_file.

Expected behavior

An error should occur and no directory should be created.

Actual behavior

No error occurs and a directory with the non-existing file name is created.

Environment:

  • OS: Linux
  • podman version: 4.3.1
  • podman compose version: 1.0.6

Additional context

Looking into podman_compose.py

As far as I can see the Podman Compose script has a setting to use either volumes or mounts https://github.com/containers/podman-compose/blob/bce40c2db30fb0ffb9264b5f51535c26f48fe983/podman_compose.py#L1459 , the prefer_volume_over_mount field, but this setting is hardcoded to true. So Podman Compose is always mounting with the -v option.

And the other thing that seems to happen is that Podman Compose always creates a directory when the file to mount does not exist https://github.com/containers/podman-compose/blob/bce40c2db30fb0ffb9264b5f51535c26f48fe983/podman_compose.py#L530 , as expected from the description above.

Volume mounting

Volume mounting is not consistent in several ways.

First inconsistency is between Docker and Podman.

Mounting a non existing file in Docker results in:

  • a directory being created when done with the -v option (docker run --rm -v ./no_file:/no_file hello-world)
  • an error when done with the --mount option (docker run --rm --mount type=bind,source=./no_file,target=/no_file hello-world)

Mounting a non existing file in Podman results always in an error.

Docker and Docker Compose are consistent, in the sense that both behaviours from Docker can be reproduced.

Podman Compose is neither consistent with Podman nor with Docker Compose.

While Podman always fails when mounting a non existing file, Podman Compose always creates a directory.

I would say that Podman Compose should be consistent with Podman. Then if Podman ever is consistent with Docker, Podman Compose will already be in a good position.

jevooq avatar Jan 31 '24 11:01 jevooq

This behaviour in podman-compose is particularly annoying when trying to mount the auth.json file (in my case /run/user/1000/containers/auth.json) which may or may not be there. It will create a directory if the file doesnt exist.

A subsequent podman login ... is then met with:

Error: get credentials: 1 error occurred:
        * reading JSON file "/run/user/1000/containers/auth.json": read /run/user/1000/containers/auth.json: is a directory

rm-hull avatar Jul 03 '24 10:07 rm-hull