podman containers are stuck in "created" state when managing the containers using cron
Environment
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 9
- Red Hat Enterprise Linux 10
- podman
Issue
- When using crontab to manage and run podman containers, containers stay in "Created" state and do not move to "Running" state unless manually started
Resolution
- Podman is failing because it can't access iptables, which is in /sbin (which is not in the default $PATH for cron jobs)
- In order to include the path, one must be including /sbin to crontab's $PATH
- For example, if the PATH variable is "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin". So append "/sbin" to this to look like "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin" and add this to the beginning of crontab. So the crontab will look like below,
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin
* * * * * podman run -itd <rest-of -the-command
Note: It is not suggested to use cron to manage podman containers due to various known issues with variables and permission instead we recommend to use systemd timers which is better for multiple reasons. https://access.redhat.com/solutions/7103618 helps understand this in details where we have discussed multiple ways to manage and schedule podman containers.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments