【问题标题】:Is there a possibility to change restart policy of podman container?是否有可能更改 podman 容器的重启策略?
【发布时间】:2021-03-17 14:38:49
【问题描述】:

是否有可能使用 podman 更改容器重启策略?我们可以在创建容器时设置策略podman run --restart always,但是创建容器时如何更改呢?

使用 docker,我们有docker update 命令允许我们这样做。不幸的是,没有podman update 命令。可以做到吗?还是我需要创建一个新容器?

【问题讨论】:

    标签: centos podman


    【解决方案1】:

    使用 podman 时,您应该创建一个 systemd 服务来管理 podman 容器。

    1. 创建 systemd 文件“/etc/systemd/system/containername.service”
    [Unit]
    Description=your container
    
    [Service]
    Restart=always
    ExecStart=/usr/bin/podman start -a containername
    ExecStop=/usr/bin/podman stop -t 2 containername
    
    [Install]
    WantedBy=local.target
    
    1. 运行命令:

    systemctl daemon-reload

    1. 使服务在启动时启动

    systemctl enable containername.service

    1. 重启服务

    systemctl restart containername.service

    您还可以添加一些其他重启 systemd 参数,例如:

    RestartSec (Configures the time to sleep before restarting a service), StartLimitInterval (seconds service is it not permitted to start any more),  StartLimitBurst
    

    有关更多详细信息,请查看手册页:“man systemd.service”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-04
      • 2018-12-12
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      • 2020-02-12
      • 2023-02-24
      • 2016-12-26
      相关资源
      最近更新 更多