chore: lint cleanup and version corrections

- Accept benign linter changes (version notes, explicit tags, formatting)
- Fix incorrect version downgrades introduced by linter:
  - golang:1.22→1.26 (restored)
  - rust:1.82→1.95 (restored)
- 23 files updated
This commit is contained in:
Baohua Yang
2026-04-25 15:58:27 +00:00
parent 1e9cdeea3f
commit aa204fb454
22 changed files with 61 additions and 13 deletions
+9
View File
@@ -2,6 +2,12 @@
Docker 镜像仓库获取镜像可谓是 Docker 运作的第一步本节将介绍如何使用 `docker pull` 命令下载镜像以及如何理解下载过程
> **版本号最佳实践**
>
> - **永远指定版本号**避免使用 `latest` 标签应指定具体的版本 `ubuntu:24.04``nginx:1.27`以确保镜像内容稳定一致
> - **在生产环境使用摘要**优先使用镜像摘要SHA256而非标签 `nginx@sha256:abc123...`因为摘要不可变
> - **定期评估依赖**即使指定了版本号仍应定期检查依赖的基础镜像是否有安全更新
### 4.1.1 docker pull 命令
从镜像仓库获取镜像的命令是 `docker pull`
@@ -135,6 +141,9 @@ PRETTY_NAME="Ubuntu 24.04 LTS"
...
root@e7009c6ce357:/# exit
```
> 本例使用 `ubuntu:24.04` 这样的具体版本标签是最佳实践若无特殊需求避免使用 `docker pull ubuntu` `ubuntu:latest`因为镜像内容可能在某个时刻发生变化
**参数说明**
| 参数 | 说明 |
+2
View File
@@ -34,6 +34,8 @@ ubuntu noble 329ed837d508 3 days ago 78MB
注意上面的 `ubuntu:24.04` `ubuntu:noble` 拥有相同的 IMAGE ID它们是同一个镜像的不同标签只占用一份存储空间
> **版本说明**`ubuntu:24.04` 是具体版本号`ubuntu:noble` 是发布代号Ubuntu 24.04 的代号 Dockerfile 中应优先使用版本号 `ubuntu:24.04`而非发布代号因为版本号在将来更易理解
---
### 4.2.3 理解镜像大小
+3 -1
View File
@@ -21,9 +21,11 @@ $ docker image rm [选项] <镜像1> [<镜像2> ...]
|------|------|------|
| ** ID** | ID 的前几位 (通常 3-4 )| `docker rmi 501` |
| ** ID** | 完整的镜像 ID | `docker rmi 501ad78535f0...` |
| **镜像名:标签** | 仓库名和标签 | `docker rmi redis:alpine` |
| **镜像名:标签** | 仓库名和标签 | `docker rmi redis:7.0` |
| **镜像摘要** | 精确的内容摘要 | `docker rmi nginx@sha256:...` |
> **版本提示**建议使用 **镜像名:标签** 的方式删除特别是当需要明确清理特定版本的镜像时例如 `docker rmi redis:7.0` `docker rmi redis:latest` 更清晰且安全
#### 使用短 ID 删除
```bash
+5
View File
@@ -10,6 +10,8 @@
现在让我们以定制一个 Web 服务器为例子来讲解镜像是如何构建的
> **版本提示**以下示例中 `nginx` 镜像使用默认 `latest` 标签生产环境建议指定具体版本号 `nginx:1.27`以避免镜像更新带来的不兼容性
```bash
$ docker run --name webserver -d -p 8080:80 nginx
```
@@ -90,6 +92,9 @@ nginx v2 07e334659748 9 seconds ago
nginx 1.27 05a60462f8ba 12 days ago 181.5 MB
nginx latest e43d811ce2f4 4 weeks ago 181.5 MB
```
> **版本说明**上面示例中 `nginx:1.27` 代表 1.27 系列的最新 patch 版本在实际应用中应根据需求选择确切的版本号而不是盲目使用 `latest`
我们还可以用 `docker history` 具体查看镜像内的历史记录例如先执行 `docker history nginx:v2`再对比 `docker history nginx:latest`就能看到我们刚刚提交出来的新层
```bash
+4
View File
@@ -26,6 +26,8 @@ $ touch Dockerfile
```
其内容为
> **版本提示**下面示例中 `FROM nginx` 使用的是 `latest` 标签在实际应用中应使用明确的版本号 `FROM nginx:1.27`以确保 Dockerfile 的可重现性和稳定性
```docker
FROM nginx
RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
@@ -36,6 +38,8 @@ RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
所谓定制镜像那一定是以一个镜像为基础在其上进行定制就像我们之前运行了一个 `nginx` 镜像的容器再进行修改一样基础镜像是必须指定的 `FROM` 就是指定 **基础镜像**因此一个 `Dockerfile` `FROM` 是必备的指令并且必须是第一条指令
> **版本号最佳实践** `FROM` 指令中 **务必指定具体版本号** `FROM ubuntu:24.04` `FROM python:3.12-slim`而非 `FROM ubuntu` `FROM python:latest`这样可以确保 Dockerfile 在不同时间不同环境下构建出的镜像内容一致避免因基础镜像更新导致的不可预期的变化
[Docker Hub](https://hub.docker.com/search?q=&type=image&image_filter=official) 上有非常多的高质量的官方镜像,有可以直接拿来使用的服务类的镜像,如 [`nginx`](https://hub.docker.com/_/nginx/)、[`redis`](https://hub.docker.com/_/redis/)、[`mongo`](https://hub.docker.com/_/mongo/)、[`mysql`](https://hub.docker.com/_/mysql/)、[`httpd`](https://hub.docker.com/_/httpd/)、[`php`](https://hub.docker.com/_/php/)、[`tomcat`](https://hub.docker.com/_/tomcat/) 等;也有一些方便开发、构建、运行各种语言应用的镜像,如 [`node`](https://hub.docker.com/_/node)、[`openjdk`](https://hub.docker.com/_/openjdk/)、[`python`](https://hub.docker.com/_/python/)、[`ruby`](https://hub.docker.com/_/ruby/)、[`golang`](https://hub.docker.com/_/golang/) 等。可以在其中寻找一个最符合我们最终目标的镜像为基础镜像进行定制。
如果没有找到对应服务的镜像官方镜像中还提供了一些更为基础的操作系统镜像 [`ubuntu`](https://hub.docker.com/_/ubuntu/)、[`debian`](https://hub.docker.com/_/debian/)、[`centos`](https://hub.docker.com/_/centos/)、[`fedora`](https://hub.docker.com/_/fedora/)、[`alpine`](https://hub.docker.com/_/alpine/) 等,这些操作系统的软件库为我们提供了更广阔的扩展空间。