I am having a container say "hello" which I am trying to start, stop and restart using podman commands.
[ podman version : 3.3.1 on RHEL ]
I am running this commands:
podman start hello
podman stop hello
podman start hello
The third command gives error as:
Error: no container with name or ID "hello" found: no such container
I ran podman ps and podman ps -a to check running and available containers resp. But none displays the "hello" container.
I found out this link of bug someone raised earlier on github, though I am not using "--rm" command and still getting this issue.
Podman stop removes the container
Anything am I missing here or any more info needs to be added to this question?
Containers are not automatically removed when you stop them unless you create the container using the --rm
flag.
You didn't specify how you created your hello
container. When creating it, are you passing --rm
to podman create
? The behavior you are describing corresponds to the scenario of creating a container with the --rm
flag.
AutoRemove
If you want to know whether the host will automatically remove a given container after exiting, then check the AutoRemove
boolean field of the HostConfig
object:
podman inspect --format \
'automatically remove: {{if .HostConfig.AutoRemove}}yes{{else}}no{{end}}' \
hello
This will display either automatically remove: yes
or automatically remove: no
.
--rm
We create the following container hello
with the --rm
flag:
podman create --rm --name hello alpine sleep 5000
We can check with podman ps -a
that the hello
container exists and has the status created.
We can also check that the AutoRemove
field is set to true:
$ podman inspect --format '{{.HostConfig.AutoRemove}}' hello
true
Then, we start the container with podman start hello
. You can check that the container is running with podman ps
.
If you now stop the container with podman stop hello
, you won't be able to see it any longer on the container list provided by podman ps -a
. That is, the container has been automatically removed.
--rm
If we repeat the same process, but without the --rm
flag at the moment of creating the hello
container, the container won't be automatically removed when it is stopped this time:
Create the container without passing --rm
:
podman create --name hello alpine sleep 5000
Check that the AutoRemove
field is set to false:
$ podman inspect --format '{{.HostConfig.AutoRemove}}' hello
false
Start it:
podman start hello
Stop it:
podman stop hello
You can check now with podman ps -a
that the container still exists.
Restart it:
podman restart hello
This time, if you want to remove the container, you need to manually do it:
podman container rm -f hello