# 镜像

#### 博客作者：联系请[点击](https://hezhiqiang.gitbook.io/about-the-author/lian-xi-zuo-zhe)，搬运不易，希望请作者喝咖啡，可以点击[联系博客作者](https://hezhiqiang.gitbook.io/about-the-author/lian-xi-zuo-zhe)

> **Docker 镜像** 是一个特殊的文件系统，除了提供容器运行时所需的程序、库、资源、配置等文件外，还包含了一些为运行时准备的一些配置参数（如匿名卷、环境变量、用户等）。镜像 **不包含** 任何动态数据，其内容在构建之后也不会被改变。

## 常用的 docker镜像相关指令[​](https://www.bkunyun.com/helpce/docs/2030/about1#%E5%9B%9B%E5%B8%B8%E7%94%A8%E7%9A%84-docker%E9%95%9C%E5%83%8F%E7%9B%B8%E5%85%B3%E6%8C%87%E4%BB%A4) <a href="#si-chang-yong-de-docker-jing-xiang-xiang-guan-zhi-ling" id="si-chang-yong-de-docker-jing-xiang-xiang-guan-zhi-ling"></a>

### 下载镜像(pull)[​](https://www.bkunyun.com/helpce/docs/2030/about1#1%E4%B8%8B%E8%BD%BD%E9%95%9C%E5%83%8Fpull) <a href="#id-1-xia-zai-jing-xiang-pull" id="id-1-xia-zai-jing-xiang-pull"></a>

```
docker pull ubuntu:20.04  # 指定版本下载
docker pull ubuntu        # 不指定默认下载最新版本
```

### 上传镜像(push）[​](https://www.bkunyun.com/helpce/docs/2030/about1#2%E4%B8%8A%E4%BC%A0%E9%95%9C%E5%83%8Fpush) <a href="#id-2-shang-chuan-jing-xiang-push" id="id-2-shang-chuan-jing-xiang-push"></a>

**docker push : 将本地的镜像上传到镜像仓库,要先登陆到镜像仓库**

**语法：**[**​**](https://www.bkunyun.com/helpce/docs/2030/about1#%E8%AF%AD%E6%B3%95-7)

```
docker push [OPTIONS] NAME[:TAG]
```

**示例：**[**​**](https://www.bkunyun.com/helpce/docs/2030/about1#%E5%AE%9E%E4%BE%8B-7)

上传本地镜像myapache:v1到镜像仓库中。

```
docker push myapache:v1
```

### 查看本地镜像列表(ls)[​](https://www.bkunyun.com/helpce/docs/2030/about1#3%E6%9F%A5%E7%9C%8B%E6%9C%AC%E5%9C%B0%E9%95%9C%E5%83%8F%E5%88%97%E8%A1%A8ls) <a href="#id-3-cha-kan-ben-di-jing-xiang-lie-biao-ls" id="id-3-cha-kan-ben-di-jing-xiang-lie-biao-ls"></a>

```
docker images
docker image ls
```

### 导出镜像(save)[​](https://www.bkunyun.com/helpce/docs/2030/about1#4%E5%AF%BC%E5%87%BA%E9%95%9C%E5%83%8Fsave) <a href="#id-4-dao-chu-jing-xiang-save" id="id-4-dao-chu-jing-xiang-save"></a>

```
docker save ubuntu:20.04 -o docker.ubuntu:20.04.tar
```

### 导入镜像(load)[​](https://www.bkunyun.com/helpce/docs/2030/about1#5%E5%AF%BC%E5%85%A5%E9%95%9C%E5%83%8Fload) <a href="#id-5-dao-ru-jing-xiang-load" id="id-5-dao-ru-jing-xiang-load"></a>

```
docker image load -i docker.ubuntu:20.04.tar
```

### 删除镜像(rm)[​](https://www.bkunyun.com/helpce/docs/2030/about1#6%E5%88%A0%E9%99%A4%E9%95%9C%E5%83%8Frm) <a href="#id-6-shan-chu-jing-xiang-rm" id="id-6-shan-chu-jing-xiang-rm"></a>

```
docker image rm 镜像ID
```

**注意事项：**

> ```
> (1)可以基于镜像的ID来删除指定的镜像文件，当然，也可以基于镜像名称和TAG编号一起删除;
> (2)很明显"docker image rm"有"docker rmi","docker remove"多个别名哟;
> (3)使用"docker rm"删除的是容器哟，而非镜像;
> (4)想要批量删除镜像，可以先停止docker服务，然后将"/var/lib/docker/*"目录全部删除，这意味着对docker进行初始化操作，因为它意味着删除了所有数据，该操作是不可逆的。
> ```

### 镜像打标签(tag)[​](https://www.bkunyun.com/helpce/docs/2030/about1#7%E9%95%9C%E5%83%8F%E6%89%93%E6%A0%87%E7%AD%BEtag) <a href="#id-7-jing-xiang-da-biao-qian-tag" id="id-7-jing-xiang-da-biao-qian-tag"></a>

**docker tag : 标记本地镜像，将其归入某一仓库。**

**语法：**[**​**](https://www.bkunyun.com/helpce/docs/2030/about1#%E8%AF%AD%E6%B3%95-8)

```
docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
```

**示例：**[**​**](https://www.bkunyun.com/helpce/docs/2030/about1#%E5%AE%9E%E4%BE%8B-8)

将镜像ubuntu:15.10标记为 runoob/ubuntu:v3 镜像。

```
docker tag ubuntu:15.10 runoob/ubuntu:v3
docker images   runoob/ubuntu:v3
```

### 清除无效镜像(prune)[​](https://www.bkunyun.com/helpce/docs/2030/about1#8%E6%B8%85%E9%99%A4%E6%97%A0%E6%95%88%E9%95%9C%E5%83%8Fprune) <a href="#id-8-qing-chu-wu-xiao-jing-xiang-prune" id="id-8-qing-chu-wu-xiao-jing-xiang-prune"></a>

> 无效的镜像指的就是没有镜像名称和标签的。

```
docker image prune 
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hezhiqiang.gitbook.io/about-the-author/yun-yuan-sheng-yun-wei-jiao-cheng/docker-ji-ben-shi-yong/jing-xiang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
