Files
BlogPosts/文章/技术类/docker的容器和镜像的删除操作.md
2025-07-22 00:44:40 +08:00

30 lines
857 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Docker容器和镜像的删除操作
## 容器和镜像的关系
简单来说,镜像是文件,容器是进程。
容器是基于镜像创建的,即容器中的进程依赖于镜像中的文件。
docker利用容器来运行应用docker容器是由docker镜像创建的运行实例。
![容器与镜像](https://i-blog.csdnimg.cn/blog_migrate/1239ccc5a805c44d9ecb6bc844ac9457.jpeg)
### 删除镜像的操作步骤
#### 一、停止正在运行的镜像创建的容器
查看正在运行的容器
```shell
docker ps
```
停止对应容器
```shell
docker stop xxx
```
xxx 是 docker ps 命令出来的容器 CONTAINER ID 的前三位
删除对应的容器
```shell
docker rm xxx
```
查看镜像
```shell
docker images
```
同理yyy 是 docker images 命令出来的镜像 IMAGE ID 的前三位
删除对应的镜像
```shell
docker rmi yyy
```