名称

podman-restart - 重启一个或多个容器

简介

podman restart [选项] 容器

podman container restart [选项] 容器

描述

restart 命令允许使用容器的 ID 或名称来重启容器。正在运行的容器会被停止并重启。已停止的容器会被启动。

选项

--all, -a

重启所有容器,无论其当前状态如何。

--cidfile

从指定文件中读取容器 ID 并重启该容器。可以指定多次。

--filter, -f=过滤器

过滤要重启的容器。可以通过多次使用 --filter 标志来给出多个过滤器。具有相同键的过滤器是包含性的,唯一的例外是 label,它是排他性的。具有不同键的过滤器总是排他性的。

下面列出了有效的过滤器

过滤器

描述

id

[ID] 容器的 ID(默认情况下 CID 前缀匹配;接受正则表达式)

name

[名称] 容器的名称(接受正则表达式)

label

[键] 或 [键=值] 分配给容器的标签

exited

[整数] 容器的退出代码

status

[状态] 容器的状态:“created”、“initialized”、“exited”、“paused”、“running”、“unknown”

ancestor

[ImageName] 用于创建容器的镜像或其后代

before

[ID] 或 [名称] 在此容器之前创建的容器

since

[ID] 或 [名称] 在此容器之后创建的容器

volume

[卷名称] 或 [挂载点目标] 挂载在容器中的卷

health

[状态] healthy 或 unhealthy

pod

[Pod] pod 的名称或完整或部分 ID

network

[网络] 网络的名称或完整 ID

until

[DateTime] 在给定持续时间或时间之前创建的容器。

command

[命令] 容器正在执行的命令,只取 argv[0]

--latest, -l

不提供名称或 ID,而是使用最新创建的容器。注意:最新创建的容器可能来自主机上 Podman 的其他用户。(此选项不适用于远程 Podman 客户端,包括 Mac 和 Windows(WSL2 除外)机器)

--running

重启所有已处于运行状态的容器。

--time, -t=秒数

强制停止前等待的秒数。使用 -1 表示无限等待。

示例

重启最新的容器。

$ podman restart -l
ec588fc80b05e19d3006bf2e8aa325f0a2e2ff1f609b7afb39176ca8e3e13467

通过部分容器 ID 重启特定容器。

$ podman restart ff6cf1
ff6cf1e5e77e6dba1efc7f3fcdb20e8b89ad8947bc0518be1fcb2c78681f226f

通过名称重启两个容器,超时时间为 4 秒。

$ podman restart --time 4 test1 test2
c3bb026838c30e5097f079fa365c9a4769d52e1017588278fa00d5c68ebc1502
17e13a63081a995136f907024bcfe50ff532917988a152da229db9d894c5a9ec

重启所有正在运行的容器。

$ podman restart --running

重启所有容器。

$ podman restart --all

使用指定文件中的 ID 重启容器。

$ podman restart --cidfile /home/user/cidfile-1
$ podman restart --cidfile /home/user/cidfile-1 --cidfile ./cidfile-2

按名称重启容器。

$ podman restart --filter name=id-name-test

按标签重启容器。

$ podman restart --filter label=app=label-test

按退出代码重启容器。

$ podman restart --filter exited=0

按状态重启容器。

$ podman restart --filter status=running

按祖先镜像重启容器。

$ podman restart --filter ancestor=nginx

重启在另一个容器之前创建的容器。

$ podman restart --filter before=second

重启在另一个容器之后创建的容器。

$ podman restart --filter since=first

按卷重启容器。

$ podman restart --filter volume=vol-filter

重启 pod 中的容器。

$ podman restart --filter pod=mypod

按网络重启容器。

$ podman restart --filter network=net-filter

重启在指定时间之前创建的容器。

$ podman restart --filter until=10s

另请参阅

podman(1)

历史

2018 年 3 月,最初由 Matt Heon mheon@redhat.com 编译