4.10. 删除镜像

使用 podman rmi 命令来移除本地存储的容器镜像。您可以通过其 ID 或名称来删除镜像。

先决条件

  • container-tools 元数据包已安装。

流程

  1. 列出本地系统上的所有镜像:

    $ podman images
    REPOSITORY                           TAG     IMAGE ID      CREATED      SIZE
    registry.redhat.io/rhel8/rsyslog     latest  4b32d14201de  7 weeks ago  228 MB
    registry.redhat.io/ubi8/ubi          latest  3269c37eae33  7 weeks ago  208 MB
    localhost/myubi                      X.Y     3269c37eae33  7 weeks ago  208 MB
  2. 列出所有容器:

    $ podman ps -a
    CONTAINER ID  IMAGE                                    COMMAND          CREATED        STATUS            PORTS   NAMES
    7ccd6001166e  registry.redhat.io/rhel8/rsyslog:latest  /bin/rsyslog.sh  6 seconds ago  Up 5 seconds ago          mysyslog

    要删除 registry.redhat.io/rhel8/rsyslog 镜像,您必须使用 podman stop 命令停止运行此镜像的所有容器。您可以通过其 ID 或名称来停止容器。

  3. 停止 mysyslog 容器:

    $ podman stop mysyslog
    7ccd6001166e9720c47fbeb077e0afd0bb635e74a1b0ede3fd34d09eaf5a52e9
  4. 删除 registry.redhat.io/rhel8/rsyslog 镜像:

    $ podman rmi registry.redhat.io/rhel8/rsyslog
    • 要删除多个镜像:

      $ podman rmi registry.redhat.io/rhel8/rsyslog registry.redhat.io/ubi8/ubi
    • 要从您的系统中删除所有镜像:

      $ podman rmi -a
    • 要删除与其有多个名称(标记)关联的镜像,请添加 -f 选项来删除它们:

      $ podman rmi -f 1de7d7b3f531
      1de7d7b3f531...

其他资源

  • podman-rmi man page