containers / containers/podman-compose
Networks and volumes are created when `--dry-run` is passed
- Dominant language
- Python
- Stars
- 6.2k
- Forks
- 622
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When running `podman-compose` with the `--dry-run` flag, any network and volume referenced by service containers are still created. This violates the semantic of `--dry-run` which specifies no actions are performed.
**To Reproduce**
Steps to reproduce the behavior:
1. place the MWE `compose.yaml` file in a directory
2. run `podman-compose -f compose.yaml -p test --in-pod false --verbose --dry-run up` inside the directory
3. observe that the network `test_srv` and the volume `test_testvol` are created
MWE compose.yaml
```yaml
services:
alpine:
image: docker.io/library/alpine:latest
networks:
- srv
volumes:
- testvol:/root
networks:
srv:
volumes:
testvol:
```
**Expected behavior**
No networks and volumes are created by `podman-compose` when invoked with `--dry-run`.
**Actual behavior**
Referenced networks and volumes are created by `podman-compose` when invoked with `--dry-run`.
**Output**
```
$ podman-compose version
podman-compose version 1.5.0
podman version 5.8.1
$ podman --version
podman version 5.8.1
$ podman-compose -f compose.yaml -p test --in-pod false --verbose --dry-run up
DEBUG:podman_compose:** excluding: set()
INFO:podman_compose:building images: ...
INFO:podman_compose:['podman', 'ps', '--filter', 'label=io.podman.compose.project=test', '-a', '--format', 'json']
INFO:podman_compose:creating missing containers: ...
DEBUG:podman_compose:podman volume inspect test_testvol || podman volume create test_testvol
INFO:podman_compose:['podman', 'volume', 'inspect', 'test_testvol']
INFO:podman_compose:['podman', 'volume', 'create', '--label', 'io.podman.compose.project=test', '--label', 'com.docker.compose.project=test', 'test_testvol']
INFO:podman_compose:['podman', 'volume', 'inspect', 'test_testvol']
INFO:podman_compose:['podman', 'network', 'exists', 'test_srv']
INFO:podman_compose:['podman', 'network', 'create', '--label', 'io.podman.compose.project=test', '--label', 'com.docker.compose.project=test', 'test_srv']
INFO:podman_compose:['podman', 'network', 'exists', 'test_srv']
INFO:podman_compose:podman create --name=test_alpine_1 --label io.podman.compose.config-hash=2d2fd0eb2c2ed7f13b7632cac115c549b272132083522daa6801c2cea3820495 --label io.podman.compose.project=test --label io.podman.compose.version=1.5.0 --label PODMAN_SYSTEMD_UNIT=podman-compose@test.service --label com.docker.compose.project=test --label com.docker.compose.project.working_dir=/home/sheaf/scratchpad/podman-tests --label com.docker.compose.project.config_files=test.yaml --label com.docker.compose.container-number=1 --label io.podman.compose.service=alpine --label com.docker.compose.service=alpine -v test_testvol:/root --network=test_srv:alias=alpine docker.io/library/alpine:latest
$ podman network ls -f name=test_srv
NETWORK ID NAME DRIVER
9ced48608379 test_srv bridge
$ podman volume ls -f name=test_testvol
DRIVER VOLUME NAME
local test_testvol
```
**Environment:**
- OS: Linux
- podman version: 5.8.1
- podman compose version: 1.5.0
**Additional context**
Note that the issue is still present on the latest commit ed3ec99699f692de5440c929ee9e7bfb116871c2. It appears that `podman-compose` unconditionally runs the necessary podman commands (seen with `--verbose`) to create networks and volumes even when `--dry-run` is passed. In contrast, `docker-compose` correctly skips the creation the referenced networks and volumes as seen below.
```sh
$ docker-compose version
Docker Compose version 5.0.2
$ DOCKER_HOST=unix://$XDG_RUNTIME_DIR/podman/podman.sock docker-compose -f compose.yaml -p test --verbose --dry-run up
[+] up 4/4
✔ Image docker.io/library/alpine:latest Pulled 0.3s
✔ Network test_srv Created 0.0s
✔ Volume test_testvol Created 0.0s
✔ Container test-alpine-1 Created 0.0s
end of 'compose up' output, interactive run is not supported in dry-run mode
$ podman network ls -f name=test_srv
NETWORK ID NAME DRIVER
$ podman volume ls -f name=test_testvol
DRIVER VOLUME NAME
```
Contributor guide
Assessment
This issue has not been assessed yet.