mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-03-24 02:35:27 +00:00
Add blank lines before headers
This commit is contained in:
@@ -115,6 +115,7 @@ flowchart TD
|
||||
> ⚠️ **笔者特别提醒**:理解这一点可以帮你避免构建出臃肿的镜像。**关键原理**:每一层的文件变化会被记录,但 **删除操作只是标记,不会真正减小镜像体积**。
|
||||
|
||||
```docker
|
||||
|
||||
## 错误示范 ❌
|
||||
|
||||
FROM ubuntu:24.04
|
||||
@@ -122,10 +123,12 @@ RUN apt-get update
|
||||
RUN apt-get install -y build-essential # 安装编译工具(约 200MB)
|
||||
RUN make && make install # 编译应用
|
||||
RUN apt-get remove build-essential # 试图删除编译工具
|
||||
|
||||
## 结果:镜像仍然包含 200MB 的编译工具!
|
||||
```
|
||||
|
||||
```docker
|
||||
|
||||
## 正确做法 ✅
|
||||
|
||||
FROM ubuntu:24.04
|
||||
@@ -135,6 +138,7 @@ RUN apt-get update && \
|
||||
apt-get remove -y build-essential && \
|
||||
apt-get autoremove -y && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
## 在同一层完成安装、使用、清理
|
||||
|
||||
```
|
||||
@@ -142,6 +146,7 @@ RUN apt-get update && \
|
||||
#### 查看镜像的分层
|
||||
|
||||
```bash
|
||||
|
||||
## 查看镜像的历史(每层的构建记录)
|
||||
|
||||
$ docker history nginx:latest
|
||||
@@ -164,6 +169,7 @@ Docker 镜像有多种标识方式:
|
||||
格式:`[仓库地址/]仓库名[:标签]`
|
||||
|
||||
```bash
|
||||
|
||||
## 完整格式
|
||||
|
||||
registry.example.com/myproject/myapp:v1.2.3
|
||||
|
||||
Reference in New Issue
Block a user