shell 脚本 : Remove hello world docker container without knowing ID

标签 shell unix ubuntu docker

我正在运行 hello world shell脚本中的docker容器:

#!/bin/bash
sudo docker run hello-world

我这样做是为了验证 docker 的安装是否正确。在此之后,我想再次删除这个容器。但由于我不知道这个新容器的 ID,我无法将其删除:
sudo docker rm hello-world

……失败了。

最佳答案

在 docker 的文档中:Explore the Application它描述了如何做到这一点。

当你docker run hello-world , 容器使用随机名称创建,您可以使用以下命令检查:

docker container ls --all

NAMES命令输出的列,您可以检查生成的名称(您可以在下面的示例图像中看到。在我的例子中是 Peace_morse)。

然后在调用 docker remove 命令时可以使用这个名称作为参数:
docker rm peaceful_morse

包含所有步骤的图像:

enter image description here

关于 shell 脚本 : Remove hello world docker container without knowing ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41730918/

相关文章:

linux - shell脚本中if else语句中的多个语句

Java 读取具有特定模式的文件

unix - Ansible:仅当Unix组存在时才将其添加到用户

ubuntu - 为什么我的 ZSH 脚本会打印出所有历史记录,但仅在 Ubuntu 上?

bash - bash 中的内置命令是什么意思?

shell - 为什么在 [ x"$VAR"= x"VALUE"] 中使用 'x'?

python - 为什么 python 子进程输出与 shell 不同?

转换为多线程套接字应用程序

ubuntu - Elasticsearch digital ocean

C++ 程序以代码 01 退出,未执行任何代码