containers / containers/podman-compose

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

Open
#828 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
6.2k
Forks
622
PR merge metrics
No merged PRs in 30d

Description

**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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.