|
| 1 | +# Debian |
| 2 | + |
| 3 | +## 🔥 自主构建镜像 |
| 4 | + |
| 5 | +- ✅ 集成: |
| 6 | + - `uv`: 用于管理 python 环境 |
| 7 | + - `tini`: 解决容器退出后, 子进程无法正常退出的问题 |
| 8 | +- ✅ 镜像: `ubuntu:22-uv`, 相比 `debian:12-uv` 占用空间更小. |
| 9 | + |
| 10 | +```ruby |
| 11 | +# run: |
| 12 | +task b12 |
| 13 | + |
| 14 | +# size: |
| 15 | +❯ docker images |
| 16 | +REPOSITORY TAG IMAGE ID CREATED SIZE |
| 17 | +ubuntu 22-uv e2a45809fec8 9 seconds ago 430MB |
| 18 | +debian 12-uv 18d0a5b7849f 28 minutes ago 577MB |
| 19 | + |
| 20 | +# 测试容器效果: |
| 21 | +docker run -it --name debain12-test debian:12-uv bash |
| 22 | +# or: |
| 23 | +docker run --rm -it debian:12-uv bash |
| 24 | + |
| 25 | +# 进入: |
| 26 | +docker exec -it debain12-test bash |
| 27 | + |
| 28 | +``` |
| 29 | + |
| 30 | +## 基镜像版本 |
| 31 | + |
| 32 | +- [debian](https://hub.docker.com/_/debian) |
| 33 | + |
| 34 | +### Slim |
| 35 | + |
| 36 | +- 特点:基于Debian,但只包含必要的软件包,以减少镜像大小。 |
| 37 | +- 适用场景:适用于那些希望保持Debian稳定性同时又需要较小镜像的应用。 |
| 38 | +- 典型大小(以Python为例): |
| 39 | + - python:3.11-slim: 大约110 MB |
| 40 | + - node:18-slim: 大约110 MB |
| 41 | + - openjdk:17-slim: 大约110 MB |
| 42 | + |
| 43 | +### Bookworm (Debian 12) |
| 44 | + |
| 45 | +- 最新稳定版:提供最新的安全更新和软件包。 |
| 46 | +- 适用场景:适合追求最新特性和安全性的项目。 |
| 47 | + |
| 48 | +### Bullseye (Debian 11) |
| 49 | + |
| 50 | +- 长期支持:提供长期的支持和维护。 |
| 51 | +- 适用场景:适合那些需要稳定性和长期支持的企业级应用。 |
| 52 | + |
| 53 | +## 镜像 |
| 54 | + |
| 55 | +```ruby |
| 56 | + |
| 57 | + |
| 58 | +docker pull debian |
| 59 | + |
| 60 | + |
| 61 | +docker pull debian:11 |
| 62 | +docker pull debian:12 |
| 63 | + |
| 64 | + |
| 65 | +# |
| 66 | +docker pull debian:11-slim |
| 67 | +docker pull debian:12-slim |
| 68 | + |
| 69 | + |
| 70 | +``` |
| 71 | + |
| 72 | +## 镜像大小对比 |
| 73 | + |
| 74 | +```ruby |
| 75 | +docker images |
| 76 | +REPOSITORY TAG IMAGE ID CREATED SIZE |
| 77 | + |
| 78 | +arm64v8/ubuntu 22.04 1c48965c5eed 7 days ago 69.2MB |
| 79 | +ubuntu 22.04 1c48965c5eed 7 days ago 69.2MB |
| 80 | + |
| 81 | +debian 12 827eb53164e3 8 days ago 139MB |
| 82 | +debian 12-slim d7d888c58aab 8 days ago 97.2MB |
| 83 | + |
| 84 | +``` |
| 85 | + |
| 86 | +## Reference |
| 87 | + |
| 88 | +### 参考 dockerfile |
| 89 | + |
| 90 | +- [uv + ubuntu](https://github.com/astral-sh/uv/blob/main/Dockerfile) |
| 91 | + |
| 92 | +### 讨论 |
| 93 | + |
| 94 | +- [2025 年了,大家服务器用的什么 Linux 版本](https://v2ex.com/t/1105283?p=3) |
| 95 | +- [大家制作 docker 镜像时操作系统层通常用哪个镜像?](https://www.v2ex.com/t/931409) |
0 commit comments