To set a restart policy for a container in Podman, you can use the --restart flag when you create the container with the podman run command. Here’s the syntax:
podman run --restart=<policy> --name <container_name> <image_name>
Example Restart Policies
-
Always Restart:
podman run --restart=always --name my_container my_image -
Restart Unless Stopped:
podman run --restart=unless-stopped --name my_container my_image -
Restart on Failure (with a maximum retry count):
podman run --restart=on-failure:5 --name my_container my_image -
No Restart (default behavior):
podman run --restart=no --name my_container my_image
Notes
- Replace
<policy>with the desired restart policy. - Replace
<container_name>with your desired name for the container. - Replace
<image_name>with the name of the image you want to run.
This will set the specified restart policy for the container when it is created.
