containers / containers/podman-compose

Exit Code and cleaning after failed pod creation

Open
#501 5 comments 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

I am running podman-compose from a script and try to catch an error if compose up failes. I want to revert all changes done before the erronous command and write it to a log-file.

```bash
podman-compose -f compose.yml --env-file user.env -p test up -d --force-recreate >> $LOG_PATH 2>&1
if [ ! $? -eq 0 ]
then
stop
echo "$(date): Error while starting TEST" >> $LOG_PATH
exit 1
fi
```

But unfortuneatly the command only outputs an error and exits with 0.

```bash
podman-compose version: 1.0.4
['podman', '--version', '']
using podman version: 4.0.3-dev
** excluding: set()
['podman', 'ps', '--filter', 'label=io.podman.compose.project=test', '-a', '--format', '{{ index .Labels "io.podman.compose.config-hash"}}']
podman pod create --name=pod_test --infra=false --share=
b7f12c401a9826a678aa5faa8f91cf7e895b12bca515171646f1c9a1bc5c6aa6
exit code: 0
['podman', 'network', 'exists', 'test_default']
['podman', 'network', 'create', '--label', 'io.podman.compose.project=test', '--label', 'com.docker.compose.project=test', 'test_default']
['podman', 'network', 'exists', 'test_default']
podman run --name=hello-world_test -d --pod=pod_test --label io.podman.compose.config-hash=945b27045c070046422e24f930b835dfaf8c59cce35ce8237a2dd150387caba1 --label io.podman.compose.project=test --label io.podman.compose.version=1.0.4 --label com.docker.compose.project=test --label com.docker.compose.project.working_dir=/test --label com.docker.compose.project.config_files=/app-compose.yml --label com.docker.compose.container-number=1 --label com.docker.compose.service=hello-world -v /www:/www --net test_default --network-alias hello-world -p 2100:8000 -u 1002:1002 62c6de28ae4c835b0175ab9eb4e0f60b61256f44f1acdcf49b311c72fff2fca5
Error: 62c6de28ae4c835b0175ab9eb4e0f60b61256f44f1acdcf49b311c72fff2fca5: image not known
exit code: 125
podman start hello-world_test
Error: no container with name or ID "hello-world_test" found: no such container
exit code: 125
```

Is there any other way to catch or trap the error myself and call my "stop" to revert all changes?

**Expected behavior**
podman-compose returns an exit code other than 0 if an error happens. \

Aditionally and optionally (would avoid lots of issues), podman-compose deletes pods, network and other things created/done before the failed command.

**Actual behavior**
podman-compose always returns an exit code 0.

**Output**

```
$ podman-compose version
podman-compose version: 1.0.4
['podman', '--version', '']
using podman version: 4.0.3-dev
podman-composer version 1.0.4
podman --version
podman version 4.0.3-dev
```

**Environment:**
- OS: Linux
- podman version: 4.0.3-dev
- podman compose version: fbff315e18fb4c98d1d7a868fbcac25060b06694

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.