diff --git a/introduction/README.md b/01_introduction/README.md similarity index 100% rename from introduction/README.md rename to 01_introduction/README.md diff --git a/01_introduction/quickstart.md b/01_introduction/quickstart.md new file mode 100644 index 0000000..b404f08 --- /dev/null +++ b/01_introduction/quickstart.md @@ -0,0 +1,65 @@ +# 快速上手 (5分钟) + +本节将通过一个简单的 Web 应用例子,带你快速体验 Docker 的核心流程:构建镜像、运行容器。 + +## 1. 准备代码 + +创建一个名为 `hello-docker` 的文件夹,并在其中创建一个 `index.html` 文件: + +```html +

Hello, Docker!

+``` + +## 2. 编写 Dockerfile + +在同级目录下创建一个名为 `Dockerfile` (无后缀) 的文件: + +```dockerfile +FROM nginx:alpine +COPY index.html /usr/share/nginx/html/index.html +``` + +## 3. 构建镜像 + +打开终端,进入该目录,执行构建命令: + +```bash +$ docker build -t my-hello-world . +``` + +* `docker build`: 构建命令 +* `-t my-hello-world`: 给镜像起个名字(标签) +* `.`: 指定上下文路径为当前目录 + +## 4. 运行容器 + +使用刚才构建的镜像启动一个容器: + +```bash +$ docker run -d -p 8080:80 my-hello-world +``` + +* `docker run`: 运行命令 +* `-d`: 后台运行 +* `-p 8080:80`: 将宿主机的 8080 端口映射到容器的 80 端口 + +## 5. 访问测试 + +打开浏览器访问 [http://localhost:8080](http://localhost:8080),你应该能看到 "Hello, Docker!"。 + +## 6. 清理 + +停止并删除容器: + +```bash +# 查看正在运行的容器 ID +$ docker ps + +# 停止容器 +$ docker stop + +# 删除容器 +$ docker rm +``` + +恭喜!你已经完成了第一次 Docker 实战。接下来请阅读 [Docker 核心概念](../02_basic_concept/README.md) 做深入了解。 diff --git a/introduction/what.md b/01_introduction/what.md similarity index 96% rename from introduction/what.md rename to 01_introduction/what.md index 402ddbd..52a5b7d 100644 --- a/introduction/what.md +++ b/01_introduction/what.md @@ -47,13 +47,13 @@ Docker 做的事情类似:无论你的应用是用 Python、Java、Node.js 还 传统虚拟机技术是虚拟出一套完整的硬件,在其上运行一个完整的操作系统,再在该系统上运行应用: -![传统虚拟化](../.gitbook/assets/virtualization.png) +![传统虚拟化](../_images/virtualization.png) ### Docker 容器 而 Docker 容器内的应用直接运行于宿主的内核,容器内没有自己的内核,也没有进行硬件虚拟: -![Docker](../.gitbook/assets/docker.png) +![Docker](../_images/docker.png) ### 关键区别 @@ -75,7 +75,7 @@ Docker 使用 [Go 语言](https://golang.google.cn/) 开发,基于 Linux 内 - **[Cgroups](https://zh.wikipedia.org/wiki/Cgroups)**:实现资源限制(CPU、内存、I/O 等) - **[Union FS](https://en.wikipedia.org/wiki/Union_mount)**:实现分层存储(如 OverlayFS) -> 如果你对这些底层技术感兴趣,可以阅读本书的[底层实现](../underly/README.md)章节。 +> 如果你对这些底层技术感兴趣,可以阅读本书的[底层实现](../13_implementation/README.md)章节。 ### Docker 架构演进 @@ -95,7 +95,7 @@ LXC ──→ libcontainer ──→ runC ──→ containerd + runC - **runC**(2015,v1.11):捐献给 OCI 的标准容器运行时 - **containerd**:高级容器运行时,管理容器生命周期 -![Docker 架构](./_images/docker-on-linux.png) +![Docker 架构](../_images/docker-on-linux.png) > `runc` 是一个 Linux 命令行工具,用于根据 [OCI 容器运行时规范](https://github.com/opencontainers/runtime-spec) 创建和运行容器。 diff --git a/introduction/why.md b/01_introduction/why.md similarity index 97% rename from introduction/why.md rename to 01_introduction/why.md index 9a9560c..74f2abe 100644 --- a/introduction/why.md +++ b/01_introduction/why.md @@ -131,10 +131,10 @@ Docker 完美契合 DevOps 的工作流程: push build 运行测试 更新 ``` -使用 [Dockerfile](../image/build.md) 定义镜像构建过程,使得: +使用 [Dockerfile](../04_image/build.md) 定义镜像构建过程,使得: - 构建过程**可重复、可追溯** - 任何人都能从代码重建完全相同的镜像 -- 配合 [GitHub Actions](../cases/ci/actions/README.md) 等 CI 系统实现自动化 +- 配合 [GitHub Actions](../14_cases/ci/actions/README.md) 等 CI 系统实现自动化 ### 5. 轻松迁移 @@ -205,4 +205,4 @@ Docker 的核心价值可以用一句话概括:**让应用的开发、测试 笔者认为,对于现代软件开发者来说,Docker 已经不是"要不要学"的问题,而是**必备技能**。无论你是前端、后端、运维还是全栈开发者,掌握 Docker 都能让你的工作更高效。 -接下来,让我们学习 Docker 的[基本概念](../basic_concept/README.md)。 +接下来,让我们学习 Docker 的[基本概念](../02_basic_concept/README.md)。 diff --git a/basic_concept/README.md b/02_basic_concept/README.md similarity index 100% rename from basic_concept/README.md rename to 02_basic_concept/README.md diff --git a/basic_concept/container.md b/02_basic_concept/container.md similarity index 94% rename from basic_concept/container.md rename to 02_basic_concept/container.md index c7fc3c8..a931eb3 100644 --- a/basic_concept/container.md +++ b/02_basic_concept/container.md @@ -125,8 +125,8 @@ $ docker rm abc123 | 方式 | 说明 | 适用场景 | |------|------|---------| -| **[数据卷(Volume)](../data_management/volume.md)** | Docker 管理的存储 | 数据库、应用数据 | -| **[绑定挂载(Bind Mount)](../data_management/bind-mounts.md)** | 挂载宿主机目录 | 开发时共享代码 | +| **[数据卷(Volume)](../07_data_network/data/volume.md)** | Docker 管理的存储 | 数据库、应用数据 | +| **[绑定挂载(Bind Mount)](../07_data_network/data/bind-mounts.md)** | 挂载宿主机目录 | 开发时共享代码 | ```bash # 使用数据卷(推荐) @@ -209,7 +209,7 @@ $ docker run ubuntu $ docker run nginx ``` -详细解释请参考[后台运行](../container/daemon.md)章节。 +详细解释请参考[后台运行](../05_container/daemon.md)章节。 ## 容器的隔离性 @@ -224,7 +224,7 @@ Docker 容器通过以下 Namespace 实现隔离: | **IPC** | 进程间通信 | 独立的信号量、消息队列 | | **USER** | 用户 | 独立的用户和组 ID | -> 想深入了解?请阅读[底层实现 - 命名空间](../underly/namespace.md)。 +> 想深入了解?请阅读[底层实现 - 命名空间](../13_implementation/namespace.md)。 ## 本章小结 @@ -240,7 +240,7 @@ Docker 容器通过以下 Namespace 实现隔离: ## 延伸阅读 -- [启动容器](../container/run.md):详细的容器启动选项 -- [后台运行](../container/daemon.md):理解容器为什么会"立即退出" -- [进入容器](../container/attach_exec.md):如何操作运行中的容器 -- [数据管理](../data_management/README.md):Volume 和数据持久化详解 +- [启动容器](../05_container/run.md):详细的容器启动选项 +- [后台运行](../05_container/daemon.md):理解容器为什么会"立即退出" +- [进入容器](../05_container/attach_exec.md):如何操作运行中的容器 +- [数据管理](../07_data_network/README.md):Volume 和数据持久化详解 diff --git a/basic_concept/image.md b/02_basic_concept/image.md similarity index 96% rename from basic_concept/image.md rename to 02_basic_concept/image.md index 69c9635..edee300 100644 --- a/basic_concept/image.md +++ b/02_basic_concept/image.md @@ -216,7 +216,7 @@ Docker 镜像可以通过以下方式获取: ## 延伸阅读 -- [获取镜像](../image/pull.md):从 Registry 下载镜像 -- [使用 Dockerfile 定制镜像](../image/build.md):创建自己的镜像 -- [Dockerfile 最佳实践](../appendix/best_practices.md):构建高质量镜像的技巧 -- [底层实现 - 联合文件系统](../underly/ufs.md):深入理解分层存储的技术原理 +- [获取镜像](../04_image/pull.md):从 Registry 下载镜像 +- [使用 Dockerfile 定制镜像](../04_image/build.md):创建自己的镜像 +- [Dockerfile 最佳实践](../15_appendix/best_practices.md):构建高质量镜像的技巧 +- [底层实现 - 联合文件系统](../13_implementation/ufs.md):深入理解分层存储的技术原理 diff --git a/basic_concept/repository.md b/02_basic_concept/repository.md similarity index 100% rename from basic_concept/repository.md rename to 02_basic_concept/repository.md diff --git a/install/README.md b/03_install/README.md similarity index 100% rename from install/README.md rename to 03_install/README.md diff --git a/.gitbook/assets/image-20200412202617411.png b/03_install/_images/image-20200412202617411.png similarity index 100% rename from .gitbook/assets/image-20200412202617411.png rename to 03_install/_images/image-20200412202617411.png diff --git a/.gitbook/assets/install-mac-apps.png b/03_install/_images/install-mac-apps.png similarity index 100% rename from .gitbook/assets/install-mac-apps.png rename to 03_install/_images/install-mac-apps.png diff --git a/.gitbook/assets/install-mac-dmg.png b/03_install/_images/install-mac-dmg.png similarity index 100% rename from .gitbook/assets/install-mac-dmg.png rename to 03_install/_images/install-mac-dmg.png diff --git a/.gitbook/assets/install-mac-example-nginx.png b/03_install/_images/install-mac-example-nginx.png similarity index 100% rename from .gitbook/assets/install-mac-example-nginx.png rename to 03_install/_images/install-mac-example-nginx.png diff --git a/.gitbook/assets/install-mac-menu.png b/03_install/_images/install-mac-menu.png similarity index 100% rename from .gitbook/assets/install-mac-menu.png rename to 03_install/_images/install-mac-menu.png diff --git a/.gitbook/assets/install-mac-menubar.png b/03_install/_images/install-mac-menubar.png similarity index 100% rename from .gitbook/assets/install-mac-menubar.png rename to 03_install/_images/install-mac-menubar.png diff --git a/.gitbook/assets/install-win-docker-app-search.png b/03_install/_images/install-win-docker-app-search.png similarity index 100% rename from .gitbook/assets/install-win-docker-app-search.png rename to 03_install/_images/install-win-docker-app-search.png diff --git a/.gitbook/assets/install-win-taskbar-circle.png b/03_install/_images/install-win-taskbar-circle.png similarity index 100% rename from .gitbook/assets/install-win-taskbar-circle.png rename to 03_install/_images/install-win-taskbar-circle.png diff --git a/install/centos.md b/03_install/centos.md similarity index 100% rename from install/centos.md rename to 03_install/centos.md diff --git a/install/debian.md b/03_install/debian.md similarity index 100% rename from install/debian.md rename to 03_install/debian.md diff --git a/install/experimental.md b/03_install/experimental.md similarity index 100% rename from install/experimental.md rename to 03_install/experimental.md diff --git a/install/fedora.md b/03_install/fedora.md similarity index 100% rename from install/fedora.md rename to 03_install/fedora.md diff --git a/install/mac.md b/03_install/mac.md similarity index 90% rename from install/mac.md rename to 03_install/mac.md index 020dd8d..e30ff38 100644 --- a/install/mac.md +++ b/03_install/mac.md @@ -22,21 +22,21 @@ $ brew install --cask docker 如同 macOS 其它软件一样,安装也非常简单,双击下载的 `.dmg` 文件,然后将那只叫 [Moby](https://www.docker.com/blog/call-me-moby-dock/) 的鲸鱼图标拖拽到 `Application` 文件夹即可(其间需要输入用户密码)。 -![](../.gitbook/assets/install-mac-dmg.png) +![](../_images/install-mac-dmg.png) ## 运行 从应用中找到 Docker 图标并点击运行。 -![](../.gitbook/assets/install-mac-apps.png) +![](../_images/install-mac-apps.png) 运行之后,会在右上角菜单栏看到多了一个鲸鱼图标,这个图标表明了 Docker 的运行状态。 -![](../.gitbook/assets/install-mac-menubar.png) +![](../_images/install-mac-menubar.png) 每次点击鲸鱼图标会弹出操作菜单。 -![](../.gitbook/assets/install-mac-menu.png) +![](../_images/install-mac-menu.png) 之后,你可以在终端通过命令检查安装后的 Docker 版本。 @@ -53,7 +53,7 @@ $ docker run -d -p 80:80 --name webserver nginx 服务运行后,可以访问 [http://localhost](http://localhost),如果看到了 "Welcome to nginx!",就说明 Docker Desktop for Mac 安装成功了。 -![](../.gitbook/assets/install-mac-example-nginx.png) +![](../_images/install-mac-example-nginx.png) 要停止 Nginx 服务器并删除执行下面的命令: diff --git a/install/mirror.md b/03_install/mirror.md similarity index 100% rename from install/mirror.md rename to 03_install/mirror.md diff --git a/install/offline.md b/03_install/offline.md similarity index 99% rename from install/offline.md rename to 03_install/offline.md index 1dadd7c..f47aa0a 100644 --- a/install/offline.md +++ b/03_install/offline.md @@ -6,7 +6,7 @@ 括号内的字母表示该操作需要在哪些服务器上执行 -![Docker-offile-install-top](../.gitbook/assets/image-20200412202617411.png) +![Docker-offile-install-top](../_images/image-20200412202617411.png) ## CentOS/Rocky/AlmaLinux 离线安装Docker diff --git a/install/raspberry-pi.md b/03_install/raspberry-pi.md similarity index 100% rename from install/raspberry-pi.md rename to 03_install/raspberry-pi.md diff --git a/install/ubuntu.md b/03_install/ubuntu.md similarity index 100% rename from install/ubuntu.md rename to 03_install/ubuntu.md diff --git a/install/windows.md b/03_install/windows.md similarity index 93% rename from install/windows.md rename to 03_install/windows.md index f14de28..bf8f567 100644 --- a/install/windows.md +++ b/03_install/windows.md @@ -26,11 +26,11 @@ $ winget install Docker.DockerDesktop 在 Windows 搜索栏输入 **Docker** 点击 **Docker Desktop** 开始运行。 -![](../.gitbook/assets/install-win-docker-app-search.png) +![](../_images/install-win-docker-app-search.png) Docker 启动之后会在 Windows 任务栏出现鲸鱼图标。 -![](../.gitbook/assets/install-win-taskbar-circle.png) +![](../_images/install-win-taskbar-circle.png) 等待片刻,当鲸鱼图标静止时,说明 Docker 启动成功,之后你可以打开 PowerShell 使用 Docker。 diff --git a/image/README.md b/04_image/README.md similarity index 100% rename from image/README.md rename to 04_image/README.md diff --git a/.gitbook/assets/images-create-nginx-docker.png b/04_image/_images/images-create-nginx-docker.png similarity index 100% rename from .gitbook/assets/images-create-nginx-docker.png rename to 04_image/_images/images-create-nginx-docker.png diff --git a/.gitbook/assets/images-mac-example-nginx.png b/04_image/_images/images-mac-example-nginx.png similarity index 100% rename from .gitbook/assets/images-mac-example-nginx.png rename to 04_image/_images/images-mac-example-nginx.png diff --git a/image/build.md b/04_image/build.md similarity index 100% rename from image/build.md rename to 04_image/build.md diff --git a/image/commit.md b/04_image/commit.md similarity index 97% rename from image/commit.md rename to 04_image/commit.md index d95ecbb..7556f3c 100644 --- a/image/commit.md +++ b/04_image/commit.md @@ -1,6 +1,6 @@ # 利用 commit 理解镜像构成 -> 注意:如果您是初学者,您可以暂时跳过后面的内容,直接学习 [容器](../container/) 一节。 +> 注意:如果您是初学者,您可以暂时跳过后面的内容,直接学习 [容器](../05_container/) 一节。 注意: `docker commit` 命令除了学习之外,还有一些特殊的应用场合,比如被入侵后保存现场等。但是,不要使用 `docker commit` 定制镜像,定制镜像应该使用 `Dockerfile` 来完成。如果你想要定制镜像请查看下一小节。 @@ -20,7 +20,7 @@ $ docker run --name webserver -d -p 80:80 nginx 直接用浏览器访问的话,我们会看到默认的 Nginx 欢迎页面。 -![](../.gitbook/assets/images-mac-example-nginx.png) +![](../_images/images-mac-example-nginx.png) 现在,假设我们非常不喜欢这个欢迎页面,我们希望改成欢迎 Docker 的文字,我们可以使用 `docker exec` 命令进入容器,修改其内容。 @@ -37,7 +37,7 @@ exit 现在我们再刷新浏览器的话,会发现内容被改变了。 -![](../.gitbook/assets/images-create-nginx-docker.png) +![](../_images/images-create-nginx-docker.png) 我们修改了容器的文件,也就是改动了容器的存储层。我们可以通过 `docker diff` 命令看到具体的改动。 diff --git a/image/demo/buildkit/Dockerfile b/04_image/demo/buildkit/Dockerfile similarity index 100% rename from image/demo/buildkit/Dockerfile rename to 04_image/demo/buildkit/Dockerfile diff --git a/image/demo/buildkit/Dockerfile.buildkit b/04_image/demo/buildkit/Dockerfile.buildkit similarity index 100% rename from image/demo/buildkit/Dockerfile.buildkit rename to 04_image/demo/buildkit/Dockerfile.buildkit diff --git a/image/demo/buildkit/aws.txt b/04_image/demo/buildkit/aws.txt similarity index 100% rename from image/demo/buildkit/aws.txt rename to 04_image/demo/buildkit/aws.txt diff --git a/image/demo/buildkit/package.json b/04_image/demo/buildkit/package.json similarity index 100% rename from image/demo/buildkit/package.json rename to 04_image/demo/buildkit/package.json diff --git a/image/demo/buildkit/src/index.js b/04_image/demo/buildkit/src/index.js similarity index 100% rename from image/demo/buildkit/src/index.js rename to 04_image/demo/buildkit/src/index.js diff --git a/image/demo/multi-arch/Dockerfile b/04_image/demo/multi-arch/Dockerfile similarity index 100% rename from image/demo/multi-arch/Dockerfile rename to 04_image/demo/multi-arch/Dockerfile diff --git a/image/demo/multistage-builds/.gitignore b/04_image/demo/multistage-builds/.gitignore similarity index 100% rename from image/demo/multistage-builds/.gitignore rename to 04_image/demo/multistage-builds/.gitignore diff --git a/image/demo/multistage-builds/Dockerfile b/04_image/demo/multistage-builds/Dockerfile similarity index 100% rename from image/demo/multistage-builds/Dockerfile rename to 04_image/demo/multistage-builds/Dockerfile diff --git a/image/demo/multistage-builds/Dockerfile.build b/04_image/demo/multistage-builds/Dockerfile.build similarity index 100% rename from image/demo/multistage-builds/Dockerfile.build rename to 04_image/demo/multistage-builds/Dockerfile.build diff --git a/image/demo/multistage-builds/Dockerfile.copy b/04_image/demo/multistage-builds/Dockerfile.copy similarity index 100% rename from image/demo/multistage-builds/Dockerfile.copy rename to 04_image/demo/multistage-builds/Dockerfile.copy diff --git a/image/demo/multistage-builds/Dockerfile.one b/04_image/demo/multistage-builds/Dockerfile.one similarity index 100% rename from image/demo/multistage-builds/Dockerfile.one rename to 04_image/demo/multistage-builds/Dockerfile.one diff --git a/image/demo/multistage-builds/app.go b/04_image/demo/multistage-builds/app.go similarity index 100% rename from image/demo/multistage-builds/app.go rename to 04_image/demo/multistage-builds/app.go diff --git a/image/demo/multistage-builds/build.sh b/04_image/demo/multistage-builds/build.sh old mode 100755 new mode 100644 similarity index 100% rename from image/demo/multistage-builds/build.sh rename to 04_image/demo/multistage-builds/build.sh diff --git a/image/dockerfile/README.md b/04_image/dockerfile/README.md similarity index 100% rename from image/dockerfile/README.md rename to 04_image/dockerfile/README.md diff --git a/image/dockerfile/add.md b/04_image/dockerfile/add.md similarity index 98% rename from image/dockerfile/add.md rename to 04_image/dockerfile/add.md index 633d3a7..facd258 100644 --- a/image/dockerfile/add.md +++ b/04_image/dockerfile/add.md @@ -218,4 +218,4 @@ RUN tar -xzf /tmp/app.tar.gz -C /app && \ - [COPY 复制文件](copy.md):基本复制操作 - [多阶段构建](../multistage-builds.md):减少镜像体积 -- [最佳实践](../../appendix/best_practices.md):Dockerfile 编写指南 +- [最佳实践](../../15_appendix/best_practices.md):Dockerfile 编写指南 diff --git a/image/dockerfile/arg.md b/04_image/dockerfile/arg.md similarity index 98% rename from image/dockerfile/arg.md rename to 04_image/dockerfile/arg.md index f36c36a..f15f252 100644 --- a/image/dockerfile/arg.md +++ b/04_image/dockerfile/arg.md @@ -234,5 +234,5 @@ FROM ${BASE_IMAGE} ## 延伸阅读 - [ENV 设置环境变量](env.md):运行时环境变量 -- [FROM 指令](../../image/build.md):基础镜像指定 +- [FROM 指令](../../04_image/build.md):基础镜像指定 - [多阶段构建](../multistage-builds.md):复杂构建场景 diff --git a/image/dockerfile/cmd.md b/04_image/dockerfile/cmd.md similarity index 97% rename from image/dockerfile/cmd.md rename to 04_image/dockerfile/cmd.md index 91edf30..bd80779 100644 --- a/image/dockerfile/cmd.md +++ b/04_image/dockerfile/cmd.md @@ -264,5 +264,5 @@ CMD ["python", "app.py"] ## 延伸阅读 - [ENTRYPOINT 入口点](entrypoint.md):固定的启动命令 -- [后台运行](../../container/daemon.md):容器前台/后台概念 -- [最佳实践](../../appendix/best_practices.md):Dockerfile 编写指南 +- [后台运行](../../05_container/daemon.md):容器前台/后台概念 +- [最佳实践](../../15_appendix/best_practices.md):Dockerfile 编写指南 diff --git a/image/dockerfile/copy.md b/04_image/dockerfile/copy.md similarity index 98% rename from image/dockerfile/copy.md rename to 04_image/dockerfile/copy.md index 7bf01fd..d9bcc53 100644 --- a/image/dockerfile/copy.md +++ b/04_image/dockerfile/copy.md @@ -258,4 +258,4 @@ COPY . . - [ADD 指令](add.md):复制和解压 - [WORKDIR 指令](workdir.md):设置工作目录 - [多阶段构建](../multistage-builds.md):优化镜像大小 -- [最佳实践](../../appendix/best_practices.md):Dockerfile 编写指南 +- [最佳实践](../../15_appendix/best_practices.md):Dockerfile 编写指南 diff --git a/image/dockerfile/entrypoint.md b/04_image/dockerfile/entrypoint.md similarity index 97% rename from image/dockerfile/entrypoint.md rename to 04_image/dockerfile/entrypoint.md index 81d4b4d..ba15c50 100644 --- a/image/dockerfile/entrypoint.md +++ b/04_image/dockerfile/entrypoint.md @@ -302,5 +302,5 @@ wait $PID ## 延伸阅读 - [CMD 容器启动命令](cmd.md):默认命令 -- [最佳实践](../../appendix/best_practices.md):启动命令设计 -- [后台运行](../../container/daemon.md):前台/后台概念 +- [最佳实践](../../15_appendix/best_practices.md):启动命令设计 +- [后台运行](../../05_container/daemon.md):前台/后台概念 diff --git a/image/dockerfile/env.md b/04_image/dockerfile/env.md similarity index 98% rename from image/dockerfile/env.md rename to 04_image/dockerfile/env.md index 23eb81c..cb52c57 100644 --- a/image/dockerfile/env.md +++ b/04_image/dockerfile/env.md @@ -245,4 +245,4 @@ ENV VAR3=value3 - [ARG 构建参数](arg.md):构建时变量 - [Compose 环境变量](../../compose/compose_file.md):Compose 中的环境变量 -- [最佳实践](../../appendix/best_practices.md):Dockerfile 编写指南 +- [最佳实践](../../15_appendix/best_practices.md):Dockerfile 编写指南 diff --git a/image/dockerfile/expose.md b/04_image/dockerfile/expose.md similarity index 100% rename from image/dockerfile/expose.md rename to 04_image/dockerfile/expose.md diff --git a/image/dockerfile/healthcheck.md b/04_image/dockerfile/healthcheck.md similarity index 98% rename from image/dockerfile/healthcheck.md rename to 04_image/dockerfile/healthcheck.md index 665e29a..2e52f8d 100644 --- a/image/dockerfile/healthcheck.md +++ b/04_image/dockerfile/healthcheck.md @@ -203,4 +203,4 @@ HEALTHCHECK --start-period=60s CMD curl -f http://localhost/ || exit 1 - [CMD 容器启动命令](cmd.md):启动主进程 - [Compose 模板文件](../../compose/compose_file.md):Compose 中的健康检查 -- [Docker 调试](../../appendix/debug.md):容器排障 +- [Docker 调试](../../15_appendix/debug.md):容器排障 diff --git a/image/dockerfile/label.md b/04_image/dockerfile/label.md similarity index 98% rename from image/dockerfile/label.md rename to 04_image/dockerfile/label.md index e7b0158..fab296a 100644 --- a/image/dockerfile/label.md +++ b/04_image/dockerfile/label.md @@ -151,4 +151,4 @@ $ docker rmi $(docker images -q --filter "label=stage=builder") ## 延伸阅读 - [OCI 标签规范](https://github.com/opencontainers/image-spec/blob/main/annotations.md) -- [Dockerfile 最佳实践](../../appendix/best_practices.md) +- [Dockerfile 最佳实践](../../15_appendix/best_practices.md) diff --git a/image/dockerfile/onbuild.md b/04_image/dockerfile/onbuild.md similarity index 97% rename from image/dockerfile/onbuild.md rename to 04_image/dockerfile/onbuild.md index 384bd5d..8c8de16 100644 --- a/image/dockerfile/onbuild.md +++ b/04_image/dockerfile/onbuild.md @@ -148,4 +148,4 @@ python:3.12-onbuild ## 延伸阅读 - [COPY 指令](copy.md):文件复制 -- [Dockerfile 最佳实践](../../appendix/best_practices.md):基础镜像设计 +- [Dockerfile 最佳实践](../../15_appendix/best_practices.md):基础镜像设计 diff --git a/image/dockerfile/references.md b/04_image/dockerfile/references.md similarity index 100% rename from image/dockerfile/references.md rename to 04_image/dockerfile/references.md diff --git a/image/dockerfile/run.md b/04_image/dockerfile/run.md similarity index 98% rename from image/dockerfile/run.md rename to 04_image/dockerfile/run.md index 0a652e7..7a36a13 100644 --- a/image/dockerfile/run.md +++ b/04_image/dockerfile/run.md @@ -178,4 +178,4 @@ RUN --mount=type=secret,id=mysecret \ - [CMD 容器启动命令](cmd.md):容器启动时的命令 - [WORKDIR 指定工作目录](workdir.md):改变目录 -- [Dockerfile 最佳实践](../../appendix/best_practices.md) +- [Dockerfile 最佳实践](../../15_appendix/best_practices.md) diff --git a/image/dockerfile/shell.md b/04_image/dockerfile/shell.md similarity index 95% rename from image/dockerfile/shell.md rename to 04_image/dockerfile/shell.md index bdde589..2487c9c 100644 --- a/image/dockerfile/shell.md +++ b/04_image/dockerfile/shell.md @@ -137,5 +137,5 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] ## 延伸阅读 -- [RUN 指令](../../image/build.md):执行命令 -- [Dockerfile 最佳实践](../../appendix/best_practices.md):错误处理与调试 +- [RUN 指令](../../04_image/build.md):执行命令 +- [Dockerfile 最佳实践](../../15_appendix/best_practices.md):错误处理与调试 diff --git a/image/dockerfile/user.md b/04_image/dockerfile/user.md similarity index 98% rename from image/dockerfile/user.md rename to 04_image/dockerfile/user.md index 652e3b3..abdc60a 100644 --- a/image/dockerfile/user.md +++ b/04_image/dockerfile/user.md @@ -270,4 +270,4 @@ RUN mkdir -p /app/data && chown appuser:appuser /app/data - [安全](../../security/README.md):容器安全实践 - [ENTRYPOINT](entrypoint.md):入口脚本中的用户切换 -- [最佳实践](../../appendix/best_practices.md):Dockerfile 安全 +- [最佳实践](../../15_appendix/best_practices.md):Dockerfile 安全 diff --git a/image/dockerfile/volume.md b/04_image/dockerfile/volume.md similarity index 97% rename from image/dockerfile/volume.md rename to 04_image/dockerfile/volume.md index c53687a..cc6c0f9 100644 --- a/image/dockerfile/volume.md +++ b/04_image/dockerfile/volume.md @@ -242,6 +242,6 @@ VOLUME /var/lib/mysql ## 延伸阅读 -- [数据卷](../../data_management/volume.md):卷的管理和使用 -- [挂载主机目录](../../data_management/bind-mounts.md):Bind Mount +- [数据卷](../../07_data_network/data/volume.md):卷的管理和使用 +- [挂载主机目录](../../07_data_network/data/bind-mounts.md):Bind Mount - [Compose 数据管理](../../compose/compose_file.md):Compose 中的卷配置 diff --git a/image/dockerfile/workdir.md b/04_image/dockerfile/workdir.md similarity index 95% rename from image/dockerfile/workdir.md rename to 04_image/dockerfile/workdir.md index 8e0c536..3f89518 100644 --- a/image/dockerfile/workdir.md +++ b/04_image/dockerfile/workdir.md @@ -192,5 +192,5 @@ $ docker run -w /tmp myimage pwd ## 延伸阅读 - [COPY 复制文件](copy.md):文件复制 -- [RUN 执行命令](../../image/build.md):执行构建命令 -- [最佳实践](../../appendix/best_practices.md):Dockerfile 编写指南 +- [RUN 执行命令](../../04_image/build.md):执行构建命令 +- [最佳实践](../../15_appendix/best_practices.md):Dockerfile 编写指南 diff --git a/image/internal.md b/04_image/internal.md similarity index 100% rename from image/internal.md rename to 04_image/internal.md diff --git a/image/list.md b/04_image/list.md similarity index 99% rename from image/list.md rename to 04_image/list.md index 92c8d0a..1565d34 100644 --- a/image/list.md +++ b/04_image/list.md @@ -255,4 +255,4 @@ $ docker images --format "{{.Repository}}:{{.Tag}}" > images.txt - [获取镜像](pull.md):从 Registry 拉取镜像 - [删除镜像](rm.md):清理本地镜像 -- [镜像](../basic_concept/image.md):理解镜像概念 +- [镜像](../02_basic_concept/image.md):理解镜像概念 diff --git a/image/multistage-builds/README.md b/04_image/multistage-builds/README.md similarity index 100% rename from image/multistage-builds/README.md rename to 04_image/multistage-builds/README.md diff --git a/image/multistage-builds/example/laravel/.dockerignore b/04_image/multistage-builds/example/laravel/.dockerignore similarity index 100% rename from image/multistage-builds/example/laravel/.dockerignore rename to 04_image/multistage-builds/example/laravel/.dockerignore diff --git a/image/multistage-builds/example/laravel/Dockerfile b/04_image/multistage-builds/example/laravel/Dockerfile similarity index 100% rename from image/multistage-builds/example/laravel/Dockerfile rename to 04_image/multistage-builds/example/laravel/Dockerfile diff --git a/image/multistage-builds/example/laravel/laravel.conf b/04_image/multistage-builds/example/laravel/laravel.conf similarity index 100% rename from image/multistage-builds/example/laravel/laravel.conf rename to 04_image/multistage-builds/example/laravel/laravel.conf diff --git a/image/multistage-builds/laravel.md b/04_image/multistage-builds/laravel.md similarity index 100% rename from image/multistage-builds/laravel.md rename to 04_image/multistage-builds/laravel.md diff --git a/image/other.md b/04_image/other.md similarity index 100% rename from image/other.md rename to 04_image/other.md diff --git a/image/pull.md b/04_image/pull.md similarity index 100% rename from image/pull.md rename to 04_image/pull.md diff --git a/image/rm.md b/04_image/rm.md similarity index 98% rename from image/rm.md rename to 04_image/rm.md index 79a2025..158a140 100644 --- a/image/rm.md +++ b/04_image/rm.md @@ -251,5 +251,5 @@ Build Cache 0 0 0B 0B ## 延伸阅读 - [列出镜像](list.md):查看和过滤镜像 -- [删除容器](../container/rm.md):清理容器 -- [数据卷](../data_management/volume.md):清理数据卷 +- [删除容器](../05_container/rm.md):清理容器 +- [数据卷](../07_data_network/data/volume.md):清理数据卷 diff --git a/container/README.md b/05_container/README.md similarity index 100% rename from container/README.md rename to 05_container/README.md diff --git a/container/attach_exec.md b/05_container/attach_exec.md similarity index 100% rename from container/attach_exec.md rename to 05_container/attach_exec.md diff --git a/container/daemon.md b/05_container/daemon.md similarity index 96% rename from container/daemon.md rename to 05_container/daemon.md index ca2edda..adcd442 100644 --- a/container/daemon.md +++ b/05_container/daemon.md @@ -213,6 +213,6 @@ $ docker attach mycontainer ## 延伸阅读 - [进入容器](attach_exec.md):如何进入正在运行的容器执行命令 -- [容器日志](../appendix/best_practices.md):生产环境的日志管理最佳实践 -- [HEALTHCHECK 健康检查](../image/dockerfile/healthcheck.md):自动检测容器内服务是否正常 +- [容器日志](../15_appendix/best_practices.md):生产环境的日志管理最佳实践 +- [HEALTHCHECK 健康检查](../04_image/dockerfile/healthcheck.md):自动检测容器内服务是否正常 - [Docker Compose](../compose/README.md):管理多个后台容器的更好方式 diff --git a/container/import_export.md b/05_container/import_export.md similarity index 100% rename from container/import_export.md rename to 05_container/import_export.md diff --git a/container/rm.md b/05_container/rm.md similarity index 97% rename from container/rm.md rename to 05_container/rm.md index 1c35197..99be069 100644 --- a/container/rm.md +++ b/05_container/rm.md @@ -234,5 +234,5 @@ $ docker system prune -a --volumes ## 延伸阅读 - [终止容器](stop.md):优雅停止容器 -- [删除镜像](../image/rm.md):清理镜像 -- [数据卷](../data_management/volume.md):数据卷管理 +- [删除镜像](../04_image/rm.md):清理镜像 +- [数据卷](../07_data_network/data/volume.md):数据卷管理 diff --git a/container/run.md b/05_container/run.md similarity index 98% rename from container/run.md rename to 05_container/run.md index bed0a0f..564b3b9 100644 --- a/container/run.md +++ b/05_container/run.md @@ -210,7 +210,7 @@ $ docker run -d -p 80:80 nginx $ docker run -v mydata:/app/data myapp ``` -详见[数据管理](../data_management/README.md)。 +详见[数据管理](../07_data_network/README.md)。 ## 本章小结 @@ -226,4 +226,4 @@ $ docker run -v mydata:/app/data myapp - [后台运行](daemon.md):理解 `-d` 参数和容器生命周期 - [进入容器](attach_exec.md):操作运行中的容器 - [网络配置](../network/README.md):理解端口映射的原理 -- [数据管理](../data_management/README.md):数据持久化方案 +- [数据管理](../07_data_network/README.md):数据持久化方案 diff --git a/container/stop.md b/05_container/stop.md similarity index 100% rename from container/stop.md rename to 05_container/stop.md diff --git a/repository/README.md b/06_repository/README.md similarity index 100% rename from repository/README.md rename to 06_repository/README.md diff --git a/repository/demo/auth/nginx.htpasswd b/06_repository/demo/auth/nginx.htpasswd similarity index 100% rename from repository/demo/auth/nginx.htpasswd rename to 06_repository/demo/auth/nginx.htpasswd diff --git a/repository/demo/config.yml b/06_repository/demo/config.yml similarity index 100% rename from repository/demo/config.yml rename to 06_repository/demo/config.yml diff --git a/repository/demo/docker-compose.yml b/06_repository/demo/docker-compose.yml similarity index 100% rename from repository/demo/docker-compose.yml rename to 06_repository/demo/docker-compose.yml diff --git a/repository/demo/root-ca.cnf b/06_repository/demo/root-ca.cnf similarity index 100% rename from repository/demo/root-ca.cnf rename to 06_repository/demo/root-ca.cnf diff --git a/repository/demo/site.cnf b/06_repository/demo/site.cnf similarity index 100% rename from repository/demo/site.cnf rename to 06_repository/demo/site.cnf diff --git a/repository/demo/ssl/docker.domain.com.crt b/06_repository/demo/ssl/docker.domain.com.crt similarity index 100% rename from repository/demo/ssl/docker.domain.com.crt rename to 06_repository/demo/ssl/docker.domain.com.crt diff --git a/repository/demo/ssl/docker.domain.com.key b/06_repository/demo/ssl/docker.domain.com.key similarity index 100% rename from repository/demo/ssl/docker.domain.com.key rename to 06_repository/demo/ssl/docker.domain.com.key diff --git a/repository/dockerhub.md b/06_repository/dockerhub.md similarity index 100% rename from repository/dockerhub.md rename to 06_repository/dockerhub.md diff --git a/repository/nexus3_registry.md b/06_repository/nexus3_registry.md similarity index 100% rename from repository/nexus3_registry.md rename to 06_repository/nexus3_registry.md diff --git a/repository/registry.md b/06_repository/registry.md similarity index 100% rename from repository/registry.md rename to 06_repository/registry.md diff --git a/repository/registry_auth.md b/06_repository/registry_auth.md similarity index 100% rename from repository/registry_auth.md rename to 06_repository/registry_auth.md diff --git a/07_data_network/README.md b/07_data_network/README.md new file mode 100644 index 0000000..cfb4f2c --- /dev/null +++ b/07_data_network/README.md @@ -0,0 +1,6 @@ +# 数据与网络管理 + +本章将介绍 Docker 中的数据管理与网络配置。 + +* [数据管理](data/README.md) +* [网络配置](network/README.md) diff --git a/data_management/README.md b/07_data_network/data/README.md similarity index 81% rename from data_management/README.md rename to 07_data_network/data/README.md index d5a76eb..46ae43e 100644 --- a/data_management/README.md +++ b/07_data_network/data/README.md @@ -1,6 +1,6 @@ # 数据管理 -![](../.gitbook/assets/types-of-mounts.png) +![](../_images/types-of-mounts.png) 这一章介绍如何在 Docker 内部以及容器之间管理数据,在容器中管理数据主要有两种方式: diff --git a/.gitbook/assets/types-of-mounts.png b/07_data_network/data/_images/types-of-mounts.png similarity index 100% rename from .gitbook/assets/types-of-mounts.png rename to 07_data_network/data/_images/types-of-mounts.png diff --git a/data_management/bind-mounts.md b/07_data_network/data/bind-mounts.md similarity index 100% rename from data_management/bind-mounts.md rename to 07_data_network/data/bind-mounts.md diff --git a/data_management/volume.md b/07_data_network/data/volume.md similarity index 75% rename from data_management/volume.md rename to 07_data_network/data/volume.md index cde7b85..dbcb363 100644 --- a/data_management/volume.md +++ b/07_data_network/data/volume.md @@ -4,13 +4,11 @@ 容器的存储层有一个关键问题:**容器删除后,数据就没了**。 -``` -┌─────────────────────────────────────────────────────────────────┐ -│ 容器存储层问题 │ -│ │ -│ 容器运行 ─────► 写入数据 ─────► 容器删除 ─────► 数据丢失! │ -│ │ -└─────────────────────────────────────────────────────────────────┘ +```mermaid +flowchart LR + Run[容器运行] --> Write[写入数据] + Write --> Delete[容器删除] + Delete -->|数据都在容器 writable 层| Lost[DATA LOST! ❌] ``` 数据卷(Volume)解决了这个问题,它的生命周期独立于容器。 @@ -31,24 +29,34 @@ ## 数据卷 vs 容器存储层 +#### 容器存储层(不推荐存储重要数据) + +```mermaid +graph TD + subgraph Container [容器] + Writable[容器存储层
Writable] + Image[镜像层
ReadOnly] + Writable --- Image + end + + Lifecycle[生命周期 = 容器生命周期] -.-> Container + Delete[容器删除] -->|导致| DataLost[数据丢失 ❌] ``` -容器存储层(不推荐存储重要数据): -┌─────────────────────────────────────────┐ -│ 容器存储层(可读写) │ -├─────────────────────────────────────────┤ -│ 镜像层(只读) │ -└─────────────────────────────────────────┘ - 生命周期 = 容器生命周期 - 容器删除 → 数据丢失 - -数据卷(推荐): -┌─────────────────────────────────────────┐ -│ 容器 │ -│ ┌─────────────────────────────────┐ │ -│ │ /app/data ──────────────────│────┼──► 数据卷 my-data -│ └─────────────────────────────────┘ │ (独立于容器) -└─────────────────────────────────────────┘ - 容器删除 → 数据卷保留 + +#### 数据卷(推荐) + +```mermaid +graph TD + subgraph Container [容器] + AppDir["/app/data"] + end + + subgraph Volume [数据卷 my-data] + Data[持久化数据] + end + + AppDir == 挂载 ==> Volume + Delete[容器删除] -.->|不会影响| Volume ``` --- @@ -351,4 +359,4 @@ $ docker volume inspect my-vol - [绑定挂载](bind-mounts.md):挂载宿主机目录 - [tmpfs 挂载](tmpfs.md):内存中的临时存储 -- [存储驱动](../underly/ufs.md):Docker 存储的底层原理 +- [存储驱动](../13_implementation/ufs.md):Docker 存储的底层原理 diff --git a/network/README.md b/07_data_network/network/README.md similarity index 73% rename from network/README.md rename to 07_data_network/network/README.md index d13c68f..bcefdce 100644 --- a/network/README.md +++ b/07_data_network/network/README.md @@ -13,29 +13,27 @@ Docker 在安装时会自动配置网络基础设施,大多数情况下开箱 Docker 启动时自动创建以下网络组件: -``` -┌────────────────────────────────────────────────────────────────┐ -│ 宿主机 │ -│ │ -│ ┌──────────────────────────────────────────────────────┐ │ -│ │ docker0 网桥 │ │ -│ │ (172.17.0.1/16) │ │ -│ │ ┌────────────┬────────────┬────────────┐ │ │ -│ │ │ │ │ │ │ │ -│ └────┼────────────┼────────────┼────────────┼──────────┘ │ -│ │ │ │ │ │ -│ ┌────┴────┐ ┌────┴────┐ ┌────┴────┐ ┌────┴────┐ │ -│ │ veth │ │ veth │ │ veth │ │ veth │ │ -│ └────┬────┘ └────┬────┘ └────┬────┘ └────┬────┘ │ -│ │ │ │ │ │ -│ ┌────┴────┐ ┌────┴────┐ ┌────┴────┐ ┌────┴────┐ │ -│ │ 容器 A │ │ 容器 B │ │ 容器 C │ │ 容器 D │ │ -│ │.17.0.2 │ │.17.0.3 │ │.17.0.4 │ │.17.0.5 │ │ -│ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ -│ │ -│ eth0 ◄──────────────────────────────────────────► 外部网络 │ -│ (192.168.1.100) │ -└────────────────────────────────────────────────────────────────┘ +```mermaid +graph TD + subgraph Host [宿主机] + eth0[物理网卡 eth0
192.168.1.100] + docker0[docker0 网桥
172.17.0.1] + + subgraph Containers + subgraph ContainerA [容器 A] + eth0_A[eth0
172.17.0.2] + end + subgraph ContainerB [容器 B] + eth0_B[eth0
172.17.0.3] + end + end + + eth0 <--> docker0 + docker0 <--> eth0_A + docker0 <--> eth0_B + end + + Internet((互联网)) <--> eth0 ``` ### 核心组件 diff --git a/network/dns.md b/07_data_network/network/dns.md similarity index 100% rename from network/dns.md rename to 07_data_network/network/dns.md diff --git a/network/port_mapping.md b/07_data_network/network/port_mapping.md similarity index 97% rename from network/port_mapping.md rename to 07_data_network/network/port_mapping.md index fe15be2..dbaf757 100644 --- a/network/port_mapping.md +++ b/07_data_network/network/port_mapping.md @@ -145,5 +145,5 @@ iptables -t nat -A DOCKER -p tcp --dport 8080 -j DNAT --to-destination 172.17.0. ## 延伸阅读 -- [EXPOSE 指令](../image/dockerfile/expose.md):在 Dockerfile 中声明端口 +- [EXPOSE 指令](../04_image/dockerfile/expose.md):在 Dockerfile 中声明端口 - [网络模式](README.md):Host 模式不需要端口映射 diff --git a/buildx/README.md b/08_buildx/README.md similarity index 100% rename from buildx/README.md rename to 08_buildx/README.md diff --git a/buildx/buildkit.md b/08_buildx/buildkit.md similarity index 100% rename from buildx/buildkit.md rename to 08_buildx/buildkit.md diff --git a/buildx/buildx.md b/08_buildx/buildx.md similarity index 100% rename from buildx/buildx.md rename to 08_buildx/buildx.md diff --git a/buildx/multi-arch-images.md b/08_buildx/multi-arch-images.md similarity index 100% rename from buildx/multi-arch-images.md rename to 08_buildx/multi-arch-images.md diff --git a/compose/README.md b/09_compose/README.md similarity index 100% rename from compose/README.md rename to 09_compose/README.md diff --git a/compose/commands.md b/09_compose/commands.md similarity index 100% rename from compose/commands.md rename to 09_compose/commands.md diff --git a/compose/compose_file.md b/09_compose/compose_file.md similarity index 100% rename from compose/compose_file.md rename to 09_compose/compose_file.md diff --git a/compose/demo/app/Dockerfile b/09_compose/demo/app/Dockerfile similarity index 100% rename from compose/demo/app/Dockerfile rename to 09_compose/demo/app/Dockerfile diff --git a/compose/demo/app/app.py b/09_compose/demo/app/app.py similarity index 100% rename from compose/demo/app/app.py rename to 09_compose/demo/app/app.py diff --git a/compose/demo/app/docker-compose.yml b/09_compose/demo/app/docker-compose.yml similarity index 100% rename from compose/demo/app/docker-compose.yml rename to 09_compose/demo/app/docker-compose.yml diff --git a/compose/demo/django/.gitignore b/09_compose/demo/django/.gitignore similarity index 100% rename from compose/demo/django/.gitignore rename to 09_compose/demo/django/.gitignore diff --git a/compose/demo/django/Dockerfile b/09_compose/demo/django/Dockerfile similarity index 100% rename from compose/demo/django/Dockerfile rename to 09_compose/demo/django/Dockerfile diff --git a/compose/demo/django/docker-compose.yml b/09_compose/demo/django/docker-compose.yml similarity index 100% rename from compose/demo/django/docker-compose.yml rename to 09_compose/demo/django/docker-compose.yml diff --git a/compose/demo/django/requirements.txt b/09_compose/demo/django/requirements.txt similarity index 100% rename from compose/demo/django/requirements.txt rename to 09_compose/demo/django/requirements.txt diff --git a/compose/demo/wordpress/docker-compose.yml b/09_compose/demo/wordpress/docker-compose.yml similarity index 100% rename from compose/demo/wordpress/docker-compose.yml rename to 09_compose/demo/wordpress/docker-compose.yml diff --git a/compose/django.md b/09_compose/django.md similarity index 98% rename from compose/django.md rename to 09_compose/django.md index d7a4cb8..7e4d78f 100644 --- a/compose/django.md +++ b/09_compose/django.md @@ -335,5 +335,5 @@ services: - [Compose 模板文件详解](compose_file.md):深入理解 docker-compose.yml 的所有配置项 - [使用 WordPress](wordpress.md):另一个 Compose 实战案例 -- [Dockerfile 最佳实践](../appendix/best_practices.md):构建更小、更安全的镜像 -- [数据管理](../data_management/README.md):Volume 和数据持久化详解 +- [Dockerfile 最佳实践](../15_appendix/best_practices.md):构建更小、更安全的镜像 +- [数据管理](../07_data_network/README.md):Volume 和数据持久化详解 diff --git a/compose/install.md b/09_compose/install.md similarity index 100% rename from compose/install.md rename to 09_compose/install.md diff --git a/compose/introduction.md b/09_compose/introduction.md similarity index 100% rename from compose/introduction.md rename to 09_compose/introduction.md diff --git a/compose/lnmp.md b/09_compose/lnmp.md similarity index 100% rename from compose/lnmp.md rename to 09_compose/lnmp.md diff --git a/compose/rails.md b/09_compose/rails.md similarity index 99% rename from compose/rails.md rename to 09_compose/rails.md index 9e39e34..65813c2 100644 --- a/compose/rails.md +++ b/09_compose/rails.md @@ -265,4 +265,4 @@ $ docker compose run --rm web bundle update - [使用 Django](django.md):Python Web 框架实战 - [Compose 模板文件](compose_file.md):配置详解 -- [数据管理](../data_management/README.md):数据持久化 +- [数据管理](../07_data_network/README.md):数据持久化 diff --git a/compose/usage.md b/09_compose/usage.md similarity index 100% rename from compose/usage.md rename to 09_compose/usage.md diff --git a/compose/wordpress.md b/09_compose/wordpress.md similarity index 98% rename from compose/wordpress.md rename to 09_compose/wordpress.md index 8e8c0fd..0a951f5 100644 --- a/compose/wordpress.md +++ b/09_compose/wordpress.md @@ -206,5 +206,5 @@ $ docker compose restart wordpress ## 延伸阅读 - [Compose 模板文件](compose_file.md):深入了解配置项 -- [数据卷](../data_management/volume.md):理解数据持久化 +- [数据卷](../07_data_network/data/volume.md):理解数据持久化 - [Docker Hub WordPress](https://hub.docker.com/_/wordpress):官方镜像文档 diff --git a/10_ops/README.md b/10_ops/README.md new file mode 100644 index 0000000..f4e3362 --- /dev/null +++ b/10_ops/README.md @@ -0,0 +1,7 @@ +# 运维管理 + +本章将介绍 Docker 的运维管理,包括监控、日志与安全。 + +* [容器监控](monitor/README.md) +* [日志管理](logs/README.md) +* [安全](security/README.md) diff --git a/10_ops/logs/README.md b/10_ops/logs/README.md new file mode 100644 index 0000000..b27a7ba --- /dev/null +++ b/10_ops/logs/README.md @@ -0,0 +1,26 @@ +# 日志管理 + +在容器化环境中,日志管理比传统环境更为复杂。容器是短暂的,意味着容器内的日志文件可能会随着容器的销毁而丢失。因此,我们需要一种集中式的日志管理方案来收集、存储和分析容器日志。 + +## Docker 日志驱动 + +Docker 提供了多种日志驱动(Log Driver)机制,允许我们将容器日志转发到不同的后端。 + +常见的日志驱动包括: + +* `json-file`: 默认驱动,将日志以 JSON 格式写入本地文件。 +* `syslog`: 将日志转发到 syslog 服务器。 +* `journald`: 将日志写入 systemd journal。 +* `fluentd`: 将日志转发到 fluentd 收集器。 +* `gelf`: 支持 GELF 协议的日志后端(如 Graylog)。 +* `awslogs`: 发送到 Amazon CloudWatch Logs。 + +## 日志管理方案 + +对于大规模的容器集群,我们通常会采用 EFK (Elasticsearch + Fluentd + Kibana) 或 ELK (Elasticsearch + Logstash + Kibana) 方案。 + +* **Elasticsearch**: 负责日志的存储和全文检索。 +* **Fluentd/Logstash**: 负责日志的采集、过滤和转发。 +* **Kibana**: 负责日志的可视化展示。 + +本章将介绍如何使用 EFK 方案来处理 Docker 容器日志。 diff --git a/10_ops/logs/elk.md b/10_ops/logs/elk.md new file mode 100644 index 0000000..8aafd6b --- /dev/null +++ b/10_ops/logs/elk.md @@ -0,0 +1,127 @@ +# ELK/EFK 堆栈 + +ELK (Elasticsearch, Logstash, Kibana) 是目前业界最流行的开源日志解决方案。而在容器领域,由于 Fluentd 更加轻量级且对容器支持更好,EFK (Elasticsearch, Fluentd, Kibana) 组合也变得非常流行。 + +## 方案架构 + +我们将采用以下架构: + +1. **Docker Container**: 容器将日志输出到标准输出 (stdout/stderr)。 +2. **Fluentd**: 作为 Docker 的 Logging Driver 或运行为守护容器,收集容器日志。 +3. **Elasticsearch**: 存储从 Fluentd 接收到的日志数据。 +4. **Kibana**: 从 Elasticsearch 读取数据并进行可视化展示。 + +## 部署流程 + +### 1. 编写 docker-compose.yml + +```yaml +version: '3' +services: + elasticsearch: + image: docker.elastic.co/elasticsearch/elasticsearch:7.17.0 + container_name: elasticsearch + environment: + - "discovery.type=single-node" + - "ES_JAVA_OPTS=-Xms512m -Xmx512m" + ports: + - "9200:9200" + volumes: + - es_data:/usr/share/elasticsearch/data + networks: + - logging + + kibana: + image: docker.elastic.co/kibana/kibana:7.17.0 + container_name: kibana + environment: + - ELASTICSEARCH_HOSTS=http://elasticsearch:9200 + ports: + - "5601:5601" + links: + - elasticsearch + networks: + - logging + + fluentd: + image: fluent/fluentd-kubernetes-daemonset:v1.14.3-debian-elasticsearch7-1.0 + container_name: fluentd + environment: + - "FLUENT_ELASTICSEARCH_HOST=elasticsearch" + - "FLUENT_ELASTICSEARCH_PORT=9200" + - "FLUENT_ELASTICSEARCH_SCHEME=http" + - "FLUENT_UID=0" + ports: + - "24224:24224" + - "24224:24224/udp" + links: + - elasticsearch + volumes: + - ./fluentd/conf:/fluentd/etc + networks: + - logging + +volumes: + es_data: + +networks: + logging: +``` + +### 2. 配置 Fluentd + +创建 `fluentd/conf/fluent.conf`: + +```conf + + @type forward + port 24224 + bind 0.0.0.0 + + + + @type copy + + @type elasticsearch + host elasticsearch + port 9200 + logstash_format true + logstash_prefix docker + logstash_dateformat %Y%m%d + include_tag_key true + type_name access_log + tag_key @log_name + flush_interval 1s + + + @type stdout + + +``` + +### 3. 配置应用容器使用 fluentd 驱动 + +启动一个测试容器,指定日志驱动为 `fluentd`: + +```bash +docker run -d \ + --log-driver=fluentd \ + --log-opt fluentd-address=localhost:24224 \ + --log-opt tag=nginx-test \ + --name nginx-test \ + nginx +``` + +**注意**: 确保 `fluentd` 容器已经启动并监听在 `localhost:24224`。在生产环境中,如果你是在不同机器上,需要将 `localhost` 替换为运行 fluentd 的主机 IP。 + +### 4. 在 Kibana 中查看日志 + +1. 访问 `http://localhost:5601`。 +2. 进入 **Management** -> **Kibana** -> **Index Patterns**。 +3. 创建新的 Index Pattern,输入 `docker-*` (我们在 fluent.conf 中配置的前缀)。 +4. 选择 `@timestamp` 作为时间字段。 +5. 去 **Discover** 页面,你就能看到 Nginx 容器的日志了。 + +## 总结 + +通过 Docker 的日志驱动机制,结合 ELK/EFK 强大的收集和分析能力,我们可以轻松构建一个能够处理海量日志的监控平台,这对于排查生产问题至关重要。 diff --git a/10_ops/monitor/README.md b/10_ops/monitor/README.md new file mode 100644 index 0000000..502fd63 --- /dev/null +++ b/10_ops/monitor/README.md @@ -0,0 +1,16 @@ +# 容器监控 + +容器化技术的普及使得应用部署变得更加灵活和高效,但也给监控带来了新的挑战。 + +在传统架构中,我们通常关注主机的 CPU、内存、磁盘 IO 等指标。而在容器环境下,除了主机层面的监控,我们更关注容器级别的资源使用情况、服务的运行状态以及编排系统的健康状况。 + +## 常见的监控方案 + +目前主流的容器监控方案包括: + +* **cAdvisor**: Google 开源的容器资源监控工具,Docker 原生支持。 +* **Prometheus**: CNCF 毕业项目,云原生时代最流行的监控系统。 +* **Grafana**: 强大的可视化平台,常与 Prometheus 配合使用。 +* **ELK/EFK Stack**: 主要用于日志管理,但也能提供一定的监控能力。 + +本章将重点介绍如何使用 Prometheus 和 Grafana 搭建一套完整的容器监控系统。 diff --git a/10_ops/monitor/prometheus.md b/10_ops/monitor/prometheus.md new file mode 100644 index 0000000..72f6ea3 --- /dev/null +++ b/10_ops/monitor/prometheus.md @@ -0,0 +1,107 @@ +# Prometheus + Grafana + +[Prometheus](https://prometheus.io/) 是一个开源的系统监控和报警工具包。它受 Google Borgmon 的启发,由 SoundCloud 在 2012 年创建。 + +## 架构简介 + +Prometheus 的主要组件包括: + +* **Prometheus Server**: 核心组件,负责收集和存储时间序列数据。 +* **Exporters**: 负责向 Prometheus 暴露监控数据(如 Node Exporter, cAdvisor)。 +* **Alertmanager**: 处理报警发送。 +* **Pushgateway**: 用于支持短生命周期的 Job 推送数据。 + +## 快速部署 + +我们可以使用 Docker Compose 快速部署一套 Prometheus + Grafana 监控环境。 + +### 1. 准备配置文件 + +创建 `prometheus.yml`: + +```yaml +global: + scrape_interval: 15s + +scrape_configs: + - job_name: 'prometheus' + static_configs: + - targets: ['localhost:9090'] + + - job_name: 'node-exporter' + static_configs: + - targets: ['node-exporter:9100'] + + - job_name: 'cadvisor' + static_configs: + - targets: ['cadvisor:8080'] +``` + +### 2. 编写 Docker Compose 文件 + +创建 `docker-compose.yml`: + +```yaml +version: '3.8' + +services: + prometheus: + image: prom/prometheus:latest + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml + ports: + - "9090:9090" + networks: + - monitoring + + grafana: + image: grafana/grafana:latest + ports: + - "3000:3000" + environment: + - GF_SECURITY_ADMIN_PASSWORD=admin + networks: + - monitoring + depends_on: + - prometheus + + node-exporter: + image: prom/node-exporter:latest + ports: + - "9100:9100" + networks: + - monitoring + + cadvisor: + image: gcr.io/cadvisor/cadvisor:latest + ports: + - "8080:8080" + volumes: + - /:/rootfs:ro + - /var/run:/var/run:ro + - /sys:/sys:ro + - /var/lib/docker/:/var/lib/docker:ro + networks: + - monitoring + +networks: + monitoring: +``` + +### 3. 启动服务 + +```bash +$ docker-compose up -d +``` + +启动后,访问以下地址: + +* Prometheus: `http://localhost:9090` +* Grafana: `http://localhost:3000` (默认账号密码: admin/admin) + +## 配置 Grafana 面板 + +1. 在 Grafana 中添加 Prometheus 数据源,URL 填写 `http://prometheus:9090`。 +2. 导入现成的 Dashboard 模板,例如 [Node Exporter Full](https://grafana.com/grafana/dashboards/1860) (ID: 1860) 和 [Docker Container](https://grafana.com/grafana/dashboards/193) (ID: 193)。 + +这样,你就拥有了一个直观的容器监控大屏。 diff --git a/security/README.md b/10_ops/security/README.md similarity index 96% rename from security/README.md rename to 10_ops/security/README.md index b6f0f44..ff593ce 100644 --- a/security/README.md +++ b/10_ops/security/README.md @@ -38,7 +38,7 @@ | IPC | 进程通信 | 隔离共享内存 | | UTS | 主机名 | 独立主机名 | -详见 [命名空间](../underly/namespace.md) 章节。 +详见 [命名空间](../13_implementation/namespace.md) 章节。 ### 2. 控制组(Cgroups) @@ -339,6 +339,6 @@ $ cosign verify --key cosign.pub myimage:tag ## 延伸阅读 -- [命名空间](../underly/namespace.md):隔离机制详解 -- [控制组](../underly/cgroups.md):资源限制详解 -- [最佳实践](../appendix/best_practices.md):Dockerfile 安全配置 +- [命名空间](../13_implementation/namespace.md):隔离机制详解 +- [控制组](../13_implementation/cgroups.md):资源限制详解 +- [最佳实践](../15_appendix/best_practices.md):Dockerfile 安全配置 diff --git a/security/control_group.md b/10_ops/security/control_group.md similarity index 100% rename from security/control_group.md rename to 10_ops/security/control_group.md diff --git a/security/daemon_sec.md b/10_ops/security/daemon_sec.md similarity index 100% rename from security/daemon_sec.md rename to 10_ops/security/daemon_sec.md diff --git a/security/kernel_capability.md b/10_ops/security/kernel_capability.md similarity index 100% rename from security/kernel_capability.md rename to 10_ops/security/kernel_capability.md diff --git a/security/kernel_ns.md b/10_ops/security/kernel_ns.md similarity index 100% rename from security/kernel_ns.md rename to 10_ops/security/kernel_ns.md diff --git a/security/other_feature.md b/10_ops/security/other_feature.md similarity index 100% rename from security/other_feature.md rename to 10_ops/security/other_feature.md diff --git a/security/summary.md b/10_ops/security/summary.md similarity index 100% rename from security/summary.md rename to 10_ops/security/summary.md diff --git a/11_orchestration/README.md b/11_orchestration/README.md new file mode 100644 index 0000000..28bcc31 --- /dev/null +++ b/11_orchestration/README.md @@ -0,0 +1,8 @@ +# 容器编排 + +本章将介绍容器编排相关的技术与工具。 + +* [Etcd 项目](etcd/README.md) +* [Kubernetes - 开源容器编排引擎](kubernetes/README.md) +* [部署 Kubernetes](setup/README.md) +* [Kubernetes 命令行 kubectl](kubectl/README.md) diff --git a/etcd/README.md b/11_orchestration/etcd/README.md similarity index 100% rename from etcd/README.md rename to 11_orchestration/etcd/README.md diff --git a/.gitbook/assets/etcd_logo.png b/11_orchestration/etcd/_images/etcd_logo.png similarity index 100% rename from .gitbook/assets/etcd_logo.png rename to 11_orchestration/etcd/_images/etcd_logo.png diff --git a/etcd/cluster.md b/11_orchestration/etcd/cluster.md similarity index 100% rename from etcd/cluster.md rename to 11_orchestration/etcd/cluster.md diff --git a/etcd/demo/cluster/docker-compose.yml b/11_orchestration/etcd/demo/cluster/docker-compose.yml similarity index 100% rename from etcd/demo/cluster/docker-compose.yml rename to 11_orchestration/etcd/demo/cluster/docker-compose.yml diff --git a/etcd/etcdctl.md b/11_orchestration/etcd/etcdctl.md similarity index 100% rename from etcd/etcdctl.md rename to 11_orchestration/etcd/etcdctl.md diff --git a/etcd/install.md b/11_orchestration/etcd/install.md similarity index 100% rename from etcd/install.md rename to 11_orchestration/etcd/install.md diff --git a/etcd/intro.md b/11_orchestration/etcd/intro.md similarity index 97% rename from etcd/intro.md rename to 11_orchestration/etcd/intro.md index 4a33df8..da808ae 100644 --- a/etcd/intro.md +++ b/11_orchestration/etcd/intro.md @@ -1,6 +1,6 @@ # 简介 -![](../.gitbook/assets/etcd_logo.png) +![](../_images/etcd_logo.png) `etcd` 是 `CoreOS` 团队于 2013 年 6 月发起的开源项目,它的目标是构建一个高可用的分布式键值(`key-value`)数据库,基于 `Go` 语言实现。我们知道,在分布式系统中,各种服务的配置信息的管理分享,服务的发现是一个很基本同时也是很重要的问题。`CoreOS` 项目就希望基于 `etcd` 来解决这一问题。 diff --git a/kubernetes/kubectl/README.md b/11_orchestration/kubectl/README.md similarity index 100% rename from kubernetes/kubectl/README.md rename to 11_orchestration/kubectl/README.md diff --git a/kubernetes/README.md b/11_orchestration/kubernetes/README.md similarity index 100% rename from kubernetes/README.md rename to 11_orchestration/kubernetes/README.md diff --git a/kubernetes/_images/k8s-singlenode-docker.png b/11_orchestration/kubernetes/_images/k8s-singlenode-docker.png similarity index 100% rename from kubernetes/_images/k8s-singlenode-docker.png rename to 11_orchestration/kubernetes/_images/k8s-singlenode-docker.png diff --git a/.gitbook/assets/k8s_architecture.png b/11_orchestration/kubernetes/_images/k8s_architecture.png similarity index 100% rename from .gitbook/assets/k8s_architecture.png rename to 11_orchestration/kubernetes/_images/k8s_architecture.png diff --git a/.gitbook/assets/kube-proxy.png b/11_orchestration/kubernetes/_images/kube-proxy.png similarity index 100% rename from .gitbook/assets/kube-proxy.png rename to 11_orchestration/kubernetes/_images/kube-proxy.png diff --git a/.gitbook/assets/kubernetes_design.jpg b/11_orchestration/kubernetes/_images/kubernetes_design.jpg similarity index 100% rename from .gitbook/assets/kubernetes_design.jpg rename to 11_orchestration/kubernetes/_images/kubernetes_design.jpg diff --git a/.gitbook/assets/kubernetes_logo.png b/11_orchestration/kubernetes/_images/kubernetes_logo.png similarity index 100% rename from .gitbook/assets/kubernetes_logo.png rename to 11_orchestration/kubernetes/_images/kubernetes_logo.png diff --git a/kubernetes/_images/kubernetes_logo.svg b/11_orchestration/kubernetes/_images/kubernetes_logo.svg similarity index 100% rename from kubernetes/_images/kubernetes_logo.svg rename to 11_orchestration/kubernetes/_images/kubernetes_logo.svg diff --git a/11_orchestration/kubernetes/advanced.md b/11_orchestration/kubernetes/advanced.md new file mode 100644 index 0000000..878afcb --- /dev/null +++ b/11_orchestration/kubernetes/advanced.md @@ -0,0 +1,61 @@ +# Kubernetes 高级特性 + +掌握了 Kubernetes 的核心概念(Pod, Service, Deployment)后,我们需要了解更多高级特性以构建生产级应用。 + +## Helm - 包管理工具 + +[Helm](https://helm.sh/) 被称为 Kubernetes 的包管理器(类似于 Linux 的 apt/yum)。它将一组 Kubernetes 资源定义文件打包为一个 **Chart**。 + +* **安装应用**:`helm install my-release bitnami/mysql` +* **版本管理**:轻松回滚应用的发布版本。 +* **模板化**:支持复杂的应用部署逻辑配置。 + +## Ingress - 服务的入口 + +Service 虽然提供了负载均衡,但通常是 4 层(TCP/UDP)。**Ingress** 提供了 7 层(HTTP/HTTPS)路由能力,充当集群的网关。 + +* **域名路由**:基于 Host 将请求转发不同服务 (api.example.com -> api-svc, web.example.com -> web-svc)。 +* **路径路由**:基于 Path 将请求转发 (/api -> api-svc, / -> web-svc)。 +* **SSL/TLS**:集中管理证书。 + +常见的 Ingress Controller有 Nginx Ingress Controller, Traefik, Istio Gateway 等。 + +## Persistent Volume (PV) 与 StorageClass + +容器内的文件是临时的。对于有状态应用(如数据库),需要持久化存储。 + +* **PVC (Persistent Volume Claim)**:用户申请存储的声明。 +* **PV (Persistent Volume)**:实际的存储资源(NFS, AWS EBS, Ceph 等)。 +* **StorageClass**:定义存储类,支持动态创建 PV。 + +## Horizontal Pod Autoscaling (HPA) + +HPA 根据 CPU 利用率或其他指标(如内存、自定义指标)自动扩缩 Deployment 或 ReplicaSet 中的 Pod 数量。 + +```yaml +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: php-apache +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: php-apache + minReplicas: 1 + maxReplicas: 10 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 +``` + +## ConfigMap 与 Secret + +* **ConfigMap**:存储非机密的配置数据(配置文件、环境变量)。 +* **Secret**:存储机密数据(密码、Token、证书),在 Etcd 中加密存储。 + +通过将配置与镜像分离,保证了容器的可移植性。 diff --git a/kubernetes/concepts.md b/11_orchestration/kubernetes/concepts.md similarity index 99% rename from kubernetes/concepts.md rename to 11_orchestration/kubernetes/concepts.md index 1960872..5587133 100644 --- a/kubernetes/concepts.md +++ b/11_orchestration/kubernetes/concepts.md @@ -1,6 +1,6 @@ # 基本概念 -![](../.gitbook/assets/kubernetes_design.jpg) +![](../_images/kubernetes_design.jpg) * 节点(`Node`):一个节点是一个运行 Kubernetes 中的主机。 * 容器组(`Pod`):一个 Pod 对应于由若干容器组成的一个容器组,同个组内的容器共享一个存储卷(volume)。 diff --git a/kubernetes/design.md b/11_orchestration/kubernetes/design.md similarity index 95% rename from kubernetes/design.md rename to 11_orchestration/kubernetes/design.md index 0c511ba..45c2a68 100644 --- a/kubernetes/design.md +++ b/11_orchestration/kubernetes/design.md @@ -15,7 +15,7 @@ 下面这张图完整展示了 Kubernetes 的运行原理。 -![Kubernetes 架构](../.gitbook/assets/k8s_architecture.png) +![Kubernetes 架构](../_images/k8s_architecture.png) 可见,Kubernetes 首先是一套分布式系统,由多个节点组成,节点分为两类:一类是属于管理平面的主节点/控制节点(Master Node);一类是属于运行平面的工作节点(Worker Node)。 @@ -46,4 +46,4 @@ * kubelet 是工作节点执行操作的 agent,负责具体的容器生命周期管理,根据从数据库中获取的信息来管理容器,并上报 pod 运行状态等; * kube-proxy 是一个简单的网络访问代理,同时也是一个 Load Balancer。它负责将访问到某个服务的请求具体分配给工作节点上的 Pod(同一类标签)。 -![Proxy 代理对服务的请求](../.gitbook/assets/kube-proxy.png) +![Proxy 代理对服务的请求](../_images/kube-proxy.png) diff --git a/kubernetes/intro.md b/11_orchestration/kubernetes/intro.md similarity index 98% rename from kubernetes/intro.md rename to 11_orchestration/kubernetes/intro.md index c570305..625d1a8 100644 --- a/kubernetes/intro.md +++ b/11_orchestration/kubernetes/intro.md @@ -1,6 +1,6 @@ # Kubernetes 简介 -![](../.gitbook/assets/kubernetes_logo.png) +![](../_images/kubernetes_logo.png) ## 什么是 Kubernetes diff --git a/11_orchestration/kubernetes/practice.md b/11_orchestration/kubernetes/practice.md new file mode 100644 index 0000000..2313377 --- /dev/null +++ b/11_orchestration/kubernetes/practice.md @@ -0,0 +1,99 @@ +# Kubernetes 实战练习 + +本章将通过一个具体的案例:部署一个 Nginx 网站,并为其配置 Service 和 Ingress,来串联前面学到的知识。 + +## 目标 + +1. 部署一个 Nginx Deployment。 +2. 创建一个 Service 暴露 Nginx。 +3. (可选)通过 Ingress 访问服务。 + +## 步骤 1:创建 Deployment + +创建一个名为 `nginx-deployment.yaml` 的文件: + +```yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + labels: + app: nginx +spec: + replicas: 2 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.24 + ports: + - containerPort: 80 +``` + +应用配置: + +```bash +kubectl apply -f nginx-deployment.yaml +``` + +## 步骤 2:创建 Service + +创建一个名为 `nginx-service.yaml` 的文件: + +```yaml +apiVersion: v1 +kind: Service +metadata: + name: nginx-service +spec: + selector: + app: nginx + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: NodePort # 使用 NodePort 方便本地测试 +``` + +应用配置: + +```bash +kubectl apply -f nginx-service.yaml +``` + +查看分配的端口: + +```bash +kubectl get svc nginx-service +``` + +如果输出端口是 `80:30080/TCP`,你可以通过 `http://:30080` 访问 Nginx。 + +## 步骤 3:模拟滚动更新 (Rolling Update) + +修改 `nginx-deployment.yaml`,将镜像版本改为 `nginx:latest`。 + +```bash +kubectl apply -f nginx-deployment.yaml +``` + +观察更新过程: + +```bash +kubectl rollout status deployment/nginx-deployment +``` + +## 步骤 4:清理资源 + +练习结束后,记得清理资源: + +```bash +kubectl delete -f nginx-service.yaml +kubectl delete -f nginx-deployment.yaml +``` diff --git a/kubernetes/setup/README.md b/11_orchestration/setup/README.md similarity index 100% rename from kubernetes/setup/README.md rename to 11_orchestration/setup/README.md diff --git a/kubernetes/setup/dashboard.md b/11_orchestration/setup/dashboard.md similarity index 100% rename from kubernetes/setup/dashboard.md rename to 11_orchestration/setup/dashboard.md diff --git a/kubernetes/setup/docker-desktop.md b/11_orchestration/setup/docker-desktop.md similarity index 100% rename from kubernetes/setup/docker-desktop.md rename to 11_orchestration/setup/docker-desktop.md diff --git a/11_orchestration/setup/k3s.md b/11_orchestration/setup/k3s.md new file mode 100644 index 0000000..cb28050 --- /dev/null +++ b/11_orchestration/setup/k3s.md @@ -0,0 +1,52 @@ +# K3s - 轻量级 Kubernetes + +[K3s](https://k3s.io/) 是一个轻量级的 Kubernetes 发行版,由 Rancher Labs 开发。它专为边缘计算、物联网、CI、ARM 等资源受限的环境设计。K3s 被打包为单个二进制文件,只有不到 100MB,但通过了 CNCF 的一致性测试。 + +## 核心特性 + +* **轻量级**:移除过时的、非必须的 Kubernetes 功能(如传统的云提供商插件),使用 SQLite 作为默认数据存储(也支持 Etcd/MySQL/Postgres)。 +* **单一二进制**:所有组件(API Server, Controller Manager, Scheduler, Kubelet, Kube-proxy)打包在一个进程中运行。 +* **开箱即用**:内置 Helm Controller、Traefik Ingress controller、ServiceLB、Local-Path-Provisioner。 +* **安全**:默认启用安全配置,基于 TLS 通信。 + +## 安装 + +### 脚本安装(Linux) + +K3s 提供了极为便捷的安装脚本: + +```bash +curl -sfL https://get.k3s.io | sh - +``` + +安装完成后,K3s 会自动启动并配置好 `systemd` 服务。 + +### 查看状态 + +```bash +sudo k3s kubectl get nodes +``` + +输出类似: +``` +NAME STATUS ROLES AGE VERSION +k3s-master Ready control-plane,master 1m v1.28.2+k3s1 +``` + +## 快速使用 + +K3s 内置了 `kubectl` 命令(通过 `k3s kubectl` 调用),为了方便,通常会建立别名或配置 `KUBECONFIG`。 + +```bash +# 读取 K3s 的配置文件 +export KUBECONFIG=/etc/rancher/k3s/k3s.yaml + +# 现在可以直接使用 kubectl +kubectl get pods -A +``` + +## 清理卸载 + +```bash +/usr/local/bin/k3s-uninstall.sh +``` diff --git a/11_orchestration/setup/kind.md b/11_orchestration/setup/kind.md new file mode 100644 index 0000000..4fa9ddf --- /dev/null +++ b/11_orchestration/setup/kind.md @@ -0,0 +1,81 @@ +# Kind - Kubernetes IN Docker + +[Kind](https://kind.sigs.k8s.io/) (Kubernetes in Docker) 是一个使用 Docker 容器作为节点运行本地 Kubernetes 集群的工具。主要用于测试 Kubernetes 本身,也非常适合本地开发和 CI 环境。 + +## 为什么选择 Kind + +* **轻量便捷**:只要有 Docker 环境即可,无需额外虚拟机。 +* **多集群支持**:可以轻松在本地启动多个集群。 +* **多版本支持**:支持指定 Kubernetes 版本进行测试。 +* **HA 支持**:支持模拟高可用集群(多 Control Plane)。 + +## 安装 Kind + +### macOS + +```bash +brew install kind +``` + +### Linux / Windows (WSL2) + +可以下载二进制文件: + +```bash +# Linux AMD64 +curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64 +chmod +x ./kind +sudo mv ./kind /usr/local/bin/kind +``` + +## 创建集群 + +最简单的创建方式: + +```bash +kind create cluster +``` + +指定集群名称: + +```bash +kind create cluster --name my-cluster +``` + +## 与集群交互 + +Kind 会自动将 kubeconfig 合并到 `~/.kube/config`。 + +```bash +kubectl cluster-info --context kind-kind +kubectl get nodes +``` + +## 高级用法:配置集群 + +创建一个 `kind-config.yaml` 来定制集群,例如映射端口到宿主机: + +```yaml +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: +- role: control-plane + extraPortMappings: + - containerPort: 80 + hostPort: 8080 + protocol: TCP +- role: worker +- role: worker +``` + +应用配置: + +```bash +kind create cluster --config kind-config.yaml +``` + +## 删除集群 + +```bash +kind delete cluster +``` diff --git a/kubernetes/setup/kubeadm-docker.md b/11_orchestration/setup/kubeadm-docker.md similarity index 100% rename from kubernetes/setup/kubeadm-docker.md rename to 11_orchestration/setup/kubeadm-docker.md diff --git a/kubernetes/setup/kubeadm.md b/11_orchestration/setup/kubeadm.md similarity index 100% rename from kubernetes/setup/kubeadm.md rename to 11_orchestration/setup/kubeadm.md diff --git a/kubernetes/setup/systemd.md b/11_orchestration/setup/systemd.md similarity index 100% rename from kubernetes/setup/systemd.md rename to 11_orchestration/setup/systemd.md diff --git a/12_ecosystem/README.md b/12_ecosystem/README.md new file mode 100644 index 0000000..67275ee --- /dev/null +++ b/12_ecosystem/README.md @@ -0,0 +1,7 @@ +# 容器生态 + +本章将介绍容器生态圈的相关项目与服务。 + +* [Fedora CoreOS](coreos/README.md) +* [容器与云计算](cloud/README.md) +* [podman - 下一代 Linux 容器工具](podman/README.md) diff --git a/cloud/README.md b/12_ecosystem/cloud/README.md similarity index 100% rename from cloud/README.md rename to 12_ecosystem/cloud/README.md diff --git a/.gitbook/assets/ECS.jpg b/12_ecosystem/cloud/_images/ECS.jpg similarity index 100% rename from .gitbook/assets/ECS.jpg rename to 12_ecosystem/cloud/_images/ECS.jpg diff --git a/.gitbook/assets/aliyun-logo.png b/12_ecosystem/cloud/_images/aliyun-logo.png similarity index 100% rename from .gitbook/assets/aliyun-logo.png rename to 12_ecosystem/cloud/_images/aliyun-logo.png diff --git a/.gitbook/assets/aws-logo.jpg b/12_ecosystem/cloud/_images/aws-logo.jpg similarity index 100% rename from .gitbook/assets/aws-logo.jpg rename to 12_ecosystem/cloud/_images/aws-logo.jpg diff --git a/.gitbook/assets/qcloud-logo.jpg b/12_ecosystem/cloud/_images/qcloud-logo.jpg similarity index 100% rename from .gitbook/assets/qcloud-logo.jpg rename to 12_ecosystem/cloud/_images/qcloud-logo.jpg diff --git a/cloud/alicloud.md b/12_ecosystem/cloud/alicloud.md similarity index 96% rename from cloud/alicloud.md rename to 12_ecosystem/cloud/alicloud.md index ef4c404..a5605d7 100644 --- a/cloud/alicloud.md +++ b/12_ecosystem/cloud/alicloud.md @@ -1,6 +1,6 @@ # 阿里云 -![阿里云](../.gitbook/assets/aliyun-logo.png) +![阿里云](../_images/aliyun-logo.png) [阿里云](https://www.aliyun.com/?source=5176.11533457\&userCode=8lx5zmtu\&type=copy) 创立于 2009 年,是中国较早的云计算平台。阿里云致力于提供安全、可靠的计算和数据处理能力。 diff --git a/cloud/aws.md b/12_ecosystem/cloud/aws.md similarity index 94% rename from cloud/aws.md rename to 12_ecosystem/cloud/aws.md index 02c7e5a..b6e8c73 100644 --- a/cloud/aws.md +++ b/12_ecosystem/cloud/aws.md @@ -1,6 +1,6 @@ # 亚马逊云 -![AWS](../.gitbook/assets/aws-logo.jpg) +![AWS](../_images/aws-logo.jpg) [AWS](https://www.amazonaws.cn),即 Amazon Web Services,是亚马逊(Amazon)公司的 IaaS 和 PaaS 平台服务。AWS 提供了一整套基础设施和应用程序服务,使用户几乎能够在云中运行一切应用程序:从企业应用程序和大数据项目,到社交游戏和移动应用程序。AWS 面向用户提供包括弹性计算、存储、数据库、应用程序在内的一整套云计算服务,能够帮助企业降低 IT 投入成本和维护成本。 @@ -8,4 +8,4 @@ 2015 年 AWS 正式发布了 EC2 容器服务(ECS)。ECS 的目的是让 Docker 容器变的更加简单,它提供了一个集群和编排的层,用来控制主机上的容器部署,以及部署之后的集群内的容器的生命周期管理。ECS 是诸如 Docker Swarm、Kubernetes、Mesos 等工具的替代,它们工作在同一个层,除了作为一个服务来提供。这些工具和 ECS 不同的地方在于,前者需要用户自己来部署和管理,而 ECS 是“作为服务”来提供的。 -![AWS 容器服务](../.gitbook/assets/ECS.jpg) +![AWS 容器服务](../_images/ECS.jpg) diff --git a/cloud/intro.md b/12_ecosystem/cloud/intro.md similarity index 100% rename from cloud/intro.md rename to 12_ecosystem/cloud/intro.md diff --git a/12_ecosystem/cloud/multicloud.md b/12_ecosystem/cloud/multicloud.md new file mode 100644 index 0000000..8564e59 --- /dev/null +++ b/12_ecosystem/cloud/multicloud.md @@ -0,0 +1,40 @@ +# 多云部署策略比较 + +企业在选择容器云平台时,通常会在 AWS EKS, Azure AKS, Google GKE 以及国内的阿里云 ACK, 腾讯云 TKE 之间进行权衡。 + +## 三大公有云 Kubernetes 服务对比 + +| 特性 | Google GKE | AWS EKS | Azure AKS | +| :--- | :--- | :--- | :--- | +| **版本更新** | 最快,通常是 K8s 新特性的首发地 | 相对保守,注重稳定性 | 跟随社区,更新速度适中 | +| **控制平面管理** | 全托管,自动升级,免费(部分区域) | 托管,每小时收费 | 全托管,控制平面免费 | +| **节点管理** | GKE Autopilot 模式完全托管节点 | Managed Node Groups 简化管理 | Virtual Machine Scale Sets | +| **网络模型** | VPC-native, 性能优秀 | AWS VPC CNI, Pod 直接获取 VPC IP | Azure CNI (消耗 IP 多) 或 Kubenet | +| **集成度** | 与 GCP 数据分析、AI 服务集成紧密 | 与 AWS IAM, ALB, CloudWatch 集成深度高 | 与 Active Directory, Azure DevOps 集成好 | + +## 多云部署策略 + +### 1. 跨云灾备 (Active-Passive) + +主要业务运行在一个云(如 AWS),数据实时复制到另一个云(如阿里云)。当主云发生故障时,流量切换到备云。 + +* **优点**: 架构相对简单,数据一致性好控制。 +* **缺点**: 资源闲置浪费,切换可能有 RTO。 + +### 2. 多活部署 (Active-Active) + +业务同时在多个云上运行,通过全局流量管理(DNS/GSLB)分发流量。 + +* **优点**: 高可用,就近接入提升用户体验。 +* **缺点**: 数据同步复杂,跨云网络延迟问题。 + +### 3. 混合云 (Hybrid Cloud) + +核心数据和敏感业务保留在私有云(IDC),弹性业务或前端业务部署在公有云。 + +* **工具**: Google Anthos, AWS Outposts, Azure Arc 都是为了解决混合云统一管理而生。 + +## 建议 + +* **技术选型**: 尽量使用标准的 Kubernetes API,避免过度依赖特定云厂商的 CRD 或专有服务,以保持应用的可移植性。 +* **IaC 管理**: 使用 Terraform 或 Pulumi 等工具统一管理多云基础设施。 diff --git a/cloud/summary.md b/12_ecosystem/cloud/summary.md similarity index 100% rename from cloud/summary.md rename to 12_ecosystem/cloud/summary.md diff --git a/cloud/tencentCloud.md b/12_ecosystem/cloud/tencentCloud.md similarity index 97% rename from cloud/tencentCloud.md rename to 12_ecosystem/cloud/tencentCloud.md index a0ae6d8..dadea2a 100644 --- a/cloud/tencentCloud.md +++ b/12_ecosystem/cloud/tencentCloud.md @@ -1,6 +1,6 @@ # 腾讯云 -![腾讯云](../.gitbook/assets/qcloud-logo.jpg) +![腾讯云](../_images/qcloud-logo.jpg) [腾讯云](https://cloud.tencent.com/act/cps/redirect?redirect=1040\&cps_key=3a5255852d5db99dcd5da4c72f05df61\&from=console) 在架构方面经过多年积累,并且有着多年对海量互联网服务的经验。不管是社交、游戏还是其他领域,都有多年的成熟产品来提供产品服务。腾讯在云端完成重要部署,为开发者及企业提供云服务、云数据、云运营等整体一站式服务方案。 diff --git a/coreos/README.md b/12_ecosystem/coreos/README.md similarity index 100% rename from coreos/README.md rename to 12_ecosystem/coreos/README.md diff --git a/coreos/demo/example.fcc b/12_ecosystem/coreos/demo/example.fcc similarity index 100% rename from coreos/demo/example.fcc rename to 12_ecosystem/coreos/demo/example.fcc diff --git a/coreos/install.md b/12_ecosystem/coreos/install.md similarity index 100% rename from coreos/install.md rename to 12_ecosystem/coreos/install.md diff --git a/coreos/intro.md b/12_ecosystem/coreos/intro.md similarity index 100% rename from coreos/intro.md rename to 12_ecosystem/coreos/intro.md diff --git a/podman/README.md b/12_ecosystem/podman/README.md similarity index 77% rename from podman/README.md rename to 12_ecosystem/podman/README.md index dd4630b..af55139 100644 --- a/podman/README.md +++ b/12_ecosystem/podman/README.md @@ -69,10 +69,35 @@ $ podman run -d --pod mypod --name webbing nginx 如果你习惯使用 `docker` 命令,可以简单地设置别名: -```bash $ alias docker=podman ``` +## 进阶用法 + +### Systemd 集成 + +Podman 可以生成 systemd 单元文件,让容器像普通系统服务一样管理。 + +```bash +# 创建容器 +$ podman run -d --name myweb -p 8080:80 nginx + +# 生成 systemd 文件 +$ podman generate systemd --name myweb --files --new + +# 启用并启动服务 +$ systemctl --user enable --now container-myweb.service +``` + +### Podman Compose + +虽然 Podman 兼容 Docker Compose,但在某些场景下你可能需要明确使用 `podman-compose`。 + +```bash +$ pip3 install podman-compose +$ podman-compose up -d +``` + ## 参考 * [Podman 官方网站](https://podman.io/) diff --git a/underly/README.md b/13_implementation/README.md similarity index 100% rename from underly/README.md rename to 13_implementation/README.md diff --git a/.gitbook/assets/docker_arch.png b/13_implementation/_images/docker_arch.png similarity index 100% rename from .gitbook/assets/docker_arch.png rename to 13_implementation/_images/docker_arch.png diff --git a/underly/arch.md b/13_implementation/arch.md similarity index 68% rename from underly/arch.md rename to 13_implementation/arch.md index 5b26def..0dd5ddf 100644 --- a/underly/arch.md +++ b/13_implementation/arch.md @@ -4,19 +4,19 @@ Docker 采用了 **C/S (客户端/服务端)** 架构。Client 向 Daemon 发送请求,Daemon 负责构建、运行和分发容器。 -``` -┌───────────────┐ ┌────────────────────────────────────┐ -│ 客户端 │ │ Docker Host │ -│ (Docker CLI) │ │ │ -│ │ │ ┌──────────┐ ┌────────────┐ │ -│ $ docker run ├────►│ │ dockerd │ │ Containers │ │ -│ $ docker pull│ │ │ (Daemon) │─────►│ │ │ -│ $ docker ps │ │ └────┬─────┘ │ □ □ │ │ -└───────────────┘ │ │ └────────────┘ │ - │ │ ┌────────────┐ │ - │ └───────────►│ Images │ │ - │ │ │ │ - └────────────────────┴────────────┘ │ +```mermaid +graph LR + Client[客户端 (Docker CLI)] -- docker run --> Dockerd + Client -- docker pull --> Dockerd + + subgraph "Docker Host" + Dockerd(dockerd
守护进程) + Containers(Containers
容器) + Images(Images
镜像) + + Dockerd -- 管理 --> Containers + Dockerd -- 管理 --> Images + end ``` --- @@ -59,21 +59,33 @@ Docker 的大脑。 当执行 `docker run -d nginx` 时,内部发生了什么? -``` -User - │ - ▼ -Docker CLI ──(REST API)──> Dockerd - │ - ▼ - Containerd ──(gRPC)──> Containerd-shim - │ - ▼ - Runc - │ - ▼ - Kernel (创建容器) - (Start & Exit) +```mermaid +flowchart TD + User((用户)) + + subgraph DockerCLI [Docker CLI] + Cmd[docker run -d nginx] + end + + subgraph DockerHost [Docker Host] + Dockerd[Dockerd] + Containerd[Containerd] + subgraph ContainerRuntime [Runtime] + Shim[Containerd-shim] + Runc[Runc] + Container[容器进程 (nginx)] + end + end + + User --> Cmd + Cmd -- 1. REST API --> Dockerd + Dockerd -- 2. gRPC --> Containerd + Containerd -- 3. 准备镜像 & Bundle --> Containerd + Containerd -- 4. Fork --> Shim + Shim -- 5. Exec --> Runc + Runc -- 6. Create Namespaces/Cgroups --> Container + Runc -.-> |7. Exit| Runc + Shim -.-> |8. Monitor IO/Exit| Container ``` 1. **CLI** 发送请求给 **Dockerd** diff --git a/underly/cgroups.md b/13_implementation/cgroups.md similarity index 98% rename from underly/cgroups.md rename to 13_implementation/cgroups.md index e30a8e9..6eb5fa3 100644 --- a/underly/cgroups.md +++ b/13_implementation/cgroups.md @@ -243,4 +243,4 @@ $ docker run -d --name cadvisor \ - [命名空间](namespace.md):资源隔离 - [安全](../security/README.md):容器安全概述 -- [Docker Stats](../container/README.md):监控容器资源 +- [Docker Stats](../05_container/README.md):监控容器资源 diff --git a/underly/container_format.md b/13_implementation/container_format.md similarity index 100% rename from underly/container_format.md rename to 13_implementation/container_format.md diff --git a/underly/namespace.md b/13_implementation/namespace.md similarity index 100% rename from underly/namespace.md rename to 13_implementation/namespace.md diff --git a/underly/network.md b/13_implementation/network.md similarity index 100% rename from underly/network.md rename to 13_implementation/network.md diff --git a/underly/ufs.md b/13_implementation/ufs.md similarity index 97% rename from underly/ufs.md rename to 13_implementation/ufs.md index 13f1646..922e9e2 100644 --- a/underly/ufs.md +++ b/13_implementation/ufs.md @@ -225,6 +225,6 @@ RUN apt-get update && \ ## 延伸阅读 -- [镜像](../basic_concept/image.md):理解镜像分层 -- [容器](../basic_concept/container.md):容器存储层 -- [构建镜像](../image/build.md):Dockerfile 层的创建 +- [镜像](../02_basic_concept/image.md):理解镜像分层 +- [容器](../02_basic_concept/container.md):容器存储层 +- [构建镜像](../04_image/build.md):Dockerfile 层的创建 diff --git a/14_cases/README.md b/14_cases/README.md new file mode 100644 index 0000000..3f5b251 --- /dev/null +++ b/14_cases/README.md @@ -0,0 +1,7 @@ +# 实战案例 + +本章将介绍 Docker 在不同场景下的实战案例。 + +* [实战案例 - 操作系统](os/README.md) +* [实战案例 - CI/CD](ci/README.md) +* [在 IDE 中使用 Docker](ide/README.md) diff --git a/cases/ci/README.md b/14_cases/ci/README.md similarity index 100% rename from cases/ci/README.md rename to 14_cases/ci/README.md diff --git a/cases/ci/actions/README.md b/14_cases/ci/actions/README.md similarity index 100% rename from cases/ci/actions/README.md rename to 14_cases/ci/actions/README.md diff --git a/14_cases/ci/devops_workflow.md b/14_cases/ci/devops_workflow.md new file mode 100644 index 0000000..64550cd --- /dev/null +++ b/14_cases/ci/devops_workflow.md @@ -0,0 +1,74 @@ +# DevOps 工作流完整示例 + +本章将演示一个基于 Docker, Kubernetes 和 Jenkins/GitLab CI 的完整 DevOps 工作流。 + +## 工作流概览 + +1. **Code**: 开发人员提交代码到 GitLab。 +2. **Build**: GitLab CI 触发构建任务。 +3. **Test**: 运行单元测试和集成测试。 +4. **Package**: 构建 Docker 镜像并推送到 Harbor/Registry。 +5. **Deploy (Staging)**: 自动部署到测试环境 Kubernetes 集群。 +6. **Verify**: 人工或自动化验证。 +7. **Release (Production)**: 审批后自动部署到生产环境。 + +## 关键配置示例 + +### 1. Dockerfile (多阶段构建) + +```dockerfile +# Build stage +FROM golang:1.18 AS builder +WORKDIR /app +COPY . . +RUN go build -o main . + +# Final stage +FROM alpine:latest +WORKDIR /app +COPY --from=builder /app/main . +CMD ["./main"] +``` + +### 2. GitLab CI (.gitlab-ci.yml) + +```yaml +stages: + - test + - build + - deploy + +unit_test: + stage: test + image: golang:1.18 + script: + - go test ./... + +build_image: + stage: build + image: docker:20.10.16 + services: + - docker:20.10.16-dind + script: + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA . + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + +deploy_staging: + stage: deploy + image: dtzar/helm-kubectl + script: + - kubectl config set-cluster k8s --server=$KUBE_URL --insecure-skip-tls-verify=true + - kubectl config set-credentials admin --token=$KUBE_TOKEN + - kubectl config set-context default --cluster=k8s --user=admin + - kubectl config use-context default + - kubectl set image deployment/myapp myapp=$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -n staging + only: + - develop +``` + +## 最佳实践 + +1. **不可变基础设施**: 一旦镜像构建完成,在各个环境(Dev, Staging, Prod)中都应该使用同一个镜像 tag (通常是 commit hash),而不是重新构建。 +2. **配置分离**: 使用 ConfigMap 和 Secret 管理环境特定的配置,不要打包进镜像。 +3. **GitOps**: 考虑引入 ArgoCD,将部署配置也作为代码存储在 Git 中,实现 Git 驱动的部署同步。 diff --git a/cases/ci/drone/.env.example b/14_cases/ci/drone/.env.example similarity index 100% rename from cases/ci/drone/.env.example rename to 14_cases/ci/drone/.env.example diff --git a/cases/ci/drone/.gitignore b/14_cases/ci/drone/.gitignore similarity index 100% rename from cases/ci/drone/.gitignore rename to 14_cases/ci/drone/.gitignore diff --git a/cases/ci/drone/README.md b/14_cases/ci/drone/README.md similarity index 97% rename from cases/ci/drone/README.md rename to 14_cases/ci/drone/README.md index aa3554a..0ab5cb0 100644 --- a/cases/ci/drone/README.md +++ b/14_cases/ci/drone/README.md @@ -86,7 +86,7 @@ $ git push origin master 打开我们部署好的 `Drone` 网站或者 Drone Cloud,即可看到构建结果。 -![](../../../.gitbook/assets/drone-build.png) +![](../../../_images/drone-build.png) 当然我们也可以把构建结果上传到 GitHub,Docker Registry,云服务商提供的对象存储,或者生产环境中。 diff --git a/.gitbook/assets/drone-build.png b/14_cases/ci/drone/_images/drone-build.png similarity index 100% rename from .gitbook/assets/drone-build.png rename to 14_cases/ci/drone/_images/drone-build.png diff --git a/cases/ci/drone/demo/.drone.yml b/14_cases/ci/drone/demo/.drone.yml similarity index 100% rename from cases/ci/drone/demo/.drone.yml rename to 14_cases/ci/drone/demo/.drone.yml diff --git a/14_cases/ci/drone/demo/README.md b/14_cases/ci/drone/demo/README.md new file mode 100644 index 0000000..d7cb1cd --- /dev/null +++ b/14_cases/ci/drone/demo/README.md @@ -0,0 +1,22 @@ +# Drone CI Demo 项目 + +这是一个基于 Go 语言编写的简单 Web 应用示例,用于演示 Drone CI 的持续集成流程。 + +## 目录结构 + +* `app.go`: 简单的 Go Web 服务器代码。 +* `.drone.yml`: Drone CI 的配置文件,定义了构建和测试流程。 +* `Dockerfile`: 定义了如何将该应用构建为 Docker 镜像。 + +## 如何运行 + +1. 确保本地已安装 Docker 环境。 +2. 进入本目录构建镜像: + ```bash + docker build -t drone-demo-app . + ``` +3. 运行容器: + ```bash + docker run -p 8080:8080 drone-demo-app + ``` +4. 访问 `http://localhost:8080` 查看效果。 diff --git a/cases/ci/drone/demo/app.go b/14_cases/ci/drone/demo/app.go similarity index 100% rename from cases/ci/drone/demo/app.go rename to 14_cases/ci/drone/demo/app.go diff --git a/cases/ci/drone/docker-compose.yml b/14_cases/ci/drone/docker-compose.yml similarity index 100% rename from cases/ci/drone/docker-compose.yml rename to 14_cases/ci/drone/docker-compose.yml diff --git a/cases/ci/drone/install.md b/14_cases/ci/drone/install.md similarity index 100% rename from cases/ci/drone/install.md rename to 14_cases/ci/drone/install.md diff --git a/ide/README.md b/14_cases/ide/README.md similarity index 100% rename from ide/README.md rename to 14_cases/ide/README.md diff --git a/ide/vsCode.md b/14_cases/ide/vsCode.md similarity index 100% rename from ide/vsCode.md rename to 14_cases/ide/vsCode.md diff --git a/cases/os/README.md b/14_cases/os/README.md similarity index 100% rename from cases/os/README.md rename to 14_cases/os/README.md diff --git a/.gitbook/assets/alpinelinux-logo.png b/14_cases/os/_images/alpinelinux-logo.png similarity index 100% rename from .gitbook/assets/alpinelinux-logo.png rename to 14_cases/os/_images/alpinelinux-logo.png diff --git a/.gitbook/assets/busybox-logo.png b/14_cases/os/_images/busybox-logo.png similarity index 100% rename from .gitbook/assets/busybox-logo.png rename to 14_cases/os/_images/busybox-logo.png diff --git a/.gitbook/assets/centos-logo.png b/14_cases/os/_images/centos-logo.png similarity index 100% rename from .gitbook/assets/centos-logo.png rename to 14_cases/os/_images/centos-logo.png diff --git a/cases/os/_images/coreos-login.png b/14_cases/os/_images/coreos-login.png similarity index 100% rename from cases/os/_images/coreos-login.png rename to 14_cases/os/_images/coreos-login.png diff --git a/cases/os/_images/coreos-logo.jpg b/14_cases/os/_images/coreos-logo.jpg similarity index 100% rename from cases/os/_images/coreos-logo.jpg rename to 14_cases/os/_images/coreos-logo.jpg diff --git a/cases/os/_images/coreos_crt.png b/14_cases/os/_images/coreos_crt.png similarity index 100% rename from cases/os/_images/coreos_crt.png rename to 14_cases/os/_images/coreos_crt.png diff --git a/cases/os/_images/coreos_list.png b/14_cases/os/_images/coreos_list.png similarity index 100% rename from cases/os/_images/coreos_list.png rename to 14_cases/os/_images/coreos_list.png diff --git a/cases/os/_images/coreos_run_ip.png b/14_cases/os/_images/coreos_run_ip.png similarity index 100% rename from cases/os/_images/coreos_run_ip.png rename to 14_cases/os/_images/coreos_run_ip.png diff --git a/.gitbook/assets/debian-logo.png b/14_cases/os/_images/debian-logo.png similarity index 100% rename from .gitbook/assets/debian-logo.png rename to 14_cases/os/_images/debian-logo.png diff --git a/cases/os/_images/docker_version.png b/14_cases/os/_images/docker_version.png similarity index 100% rename from cases/os/_images/docker_version.png rename to 14_cases/os/_images/docker_version.png diff --git a/.gitbook/assets/fedora-logo.png b/14_cases/os/_images/fedora-logo.png similarity index 100% rename from .gitbook/assets/fedora-logo.png rename to 14_cases/os/_images/fedora-logo.png diff --git a/cases/os/_images/php_pulling.png b/14_cases/os/_images/php_pulling.png similarity index 100% rename from cases/os/_images/php_pulling.png rename to 14_cases/os/_images/php_pulling.png diff --git a/.gitbook/assets/ubuntu-logo.jpg b/14_cases/os/_images/ubuntu-logo.jpg similarity index 100% rename from .gitbook/assets/ubuntu-logo.jpg rename to 14_cases/os/_images/ubuntu-logo.jpg diff --git a/cases/os/_images/vmware_coreos.png b/14_cases/os/_images/vmware_coreos.png similarity index 100% rename from cases/os/_images/vmware_coreos.png rename to 14_cases/os/_images/vmware_coreos.png diff --git a/cases/os/alpine.md b/14_cases/os/alpine.md similarity index 97% rename from cases/os/alpine.md rename to 14_cases/os/alpine.md index 46be19f..756f096 100644 --- a/cases/os/alpine.md +++ b/14_cases/os/alpine.md @@ -2,7 +2,7 @@ ## 简介 -![Alpine Linux 操作系统](../../.gitbook/assets/alpinelinux-logo.png) +![Alpine Linux 操作系统](../../_images/alpinelinux-logo.png) `Alpine` 操作系统是一个面向安全的轻型 `Linux` 发行版。它不同于通常 `Linux` 发行版,`Alpine` 采用了 `musl libc` 和 `busybox` 以减小系统的体积和运行时资源消耗,但功能上比 `busybox` 又完善的多,因此得到开源社区越来越多的青睐。在保持瘦身的同时,`Alpine` 还提供了自己的包管理工具 `apk`,可以通过 `https://pkgs.alpinelinux.org/packages` 网站上查询包信息,也可以直接通过 `apk` 命令直接查询和安装各种软件。 diff --git a/cases/os/busybox.md b/14_cases/os/busybox.md similarity index 98% rename from cases/os/busybox.md rename to 14_cases/os/busybox.md index 51a47da..cf8cfa5 100644 --- a/cases/os/busybox.md +++ b/14_cases/os/busybox.md @@ -2,7 +2,7 @@ ## 简介 -![Busybox - Linux 瑞士军刀](../../.gitbook/assets/busybox-logo.png) +![Busybox - Linux 瑞士军刀](../../_images/busybox-logo.png) `BusyBox` 是一个集成了一百多个最常用 Linux 命令和工具(如 `cat`、`echo`、`grep`、`mount`、`telnet` 等)的精简工具箱,它只需要几 MB 的大小,很方便进行各种快速验证,被誉为“Linux 系统的瑞士军刀”。 diff --git a/cases/os/centos.md b/14_cases/os/centos.md similarity index 95% rename from cases/os/centos.md rename to 14_cases/os/centos.md index 824c0e5..4d4a360 100644 --- a/cases/os/centos.md +++ b/14_cases/os/centos.md @@ -4,7 +4,7 @@ `CentOS` 和 `Fedora` 都是基于 `Redhat` 的常见 Linux 分支。`CentOS` 是目前企业级服务器的常用操作系统;`Fedora` 则主要面向个人桌面用户。 -![CentOS 操作系统](../../.gitbook/assets/centos-logo.png) +![CentOS 操作系统](../../_images/centos-logo.png) CentOS(Community Enterprise Operating System,中文意思是:社区企业操作系统),它是基于 `Red Hat Enterprise Linux` 源代码编译而成。由于 `CentOS` 与 `Redhat Linux` 源于相同的代码基础,所以很多成本敏感且需要高稳定性的公司就使用 `CentOS` 来替代商业版 `Red Hat Enterprise Linux`。`CentOS` 自身不包含闭源软件。 @@ -27,7 +27,7 @@ CentOS Linux release 7.9.2009 (Core) ## Fedora 系统简介 -![Fedora 操作系统](../../.gitbook/assets/fedora-logo.png) +![Fedora 操作系统](../../_images/fedora-logo.png) `Fedora` 由 `Fedora Project` 社区开发,红帽公司赞助的 `Linux` 发行版。它的目标是创建一套新颖、多功能并且自由和开源的操作系统。`Fedora` 的功能对于用户而言,它是一套功能完备的,可以更新的免费操作系统,而对赞助商 `Red Hat` 而言,它是许多新技术的测试平台。被认为可用的技术最终会加入到 `Red Hat Enterprise Linux` 中。 diff --git a/cases/os/debian.md b/14_cases/os/debian.md similarity index 98% rename from cases/os/debian.md rename to 14_cases/os/debian.md index 91db617..c7cf451 100644 --- a/cases/os/debian.md +++ b/14_cases/os/debian.md @@ -4,7 +4,7 @@ ## Debian 系统简介 -![Debian 操作系统](../../.gitbook/assets/debian-logo.png) +![Debian 操作系统](../../_images/debian-logo.png) `Debian` 是由 `GPL` 和其他自由软件许可协议授权的自由软件组成的操作系统,由 **Debian 计划(Debian Project)** 组织维护。**Debian 计划** 是一个独立的、分散的组织,由 `3000` 人志愿者组成,接受世界多个非盈利组织的资金支持,`Software in the Public Interest` 提供支持并持有商标作为保护机构。`Debian` 以其坚守 `Unix` 和自由软件的精神,以及其给予用户的众多选择而闻名。现时 `Debian` 包括了超过 `25,000` 个软件包并支持 `12` 个计算机系统结构。 @@ -26,7 +26,7 @@ Debian GNU/Linux 8 ## Ubuntu 系统简介 -![Ubuntu 操作系统](../../.gitbook/assets/ubuntu-logo.jpg) +![Ubuntu 操作系统](../../_images/ubuntu-logo.jpg) `Ubuntu` 是一个以桌面应用为主的 `GNU/Linux` 操作系统,其名称来自非洲南部祖鲁语或豪萨语的“ubuntu”一词(官方译名“友帮拓”,另有“吾帮托”、“乌班图”、“有奔头”或“乌斑兔”等译名)。`Ubuntu` 意思是“人性”以及“我的存在是因为大家的存在”,是非洲传统的一种价值观,类似华人社会的“仁爱”思想。 `Ubuntu` 基于 `Debian` 发行版和 `GNOME/Unity` 桌面环境,与 `Debian` 的不同在于它每 6 个月会发布一个新版本,每 2 年推出一个长期支持 **(Long Term Support,LTS)** 版本,一般支持 3 年时间。 diff --git a/cases/os/summary.md b/14_cases/os/summary.md similarity index 100% rename from cases/os/summary.md rename to 14_cases/os/summary.md diff --git a/15_appendix/README.md b/15_appendix/README.md new file mode 100644 index 0000000..8c38302 --- /dev/null +++ b/15_appendix/README.md @@ -0,0 +1,12 @@ +# 附录 + +本章包含了 Docker 相关的参考资料、常见问题解答以及最佳实践指南,旨在为读者提供便捷的查阅工具。 + +## 目录 + +* [**常见问题总结 (FAQ)**](faq/README.md):汇总了学习和使用 Docker 过程中的常见问题与错误解决方案。 +* [**热门镜像介绍**](repo/README.md):详细介绍了 Nginx, MySQL, Redis 等常用官方镜像的使用方法。 +* [**Docker 命令查询**](command/README.md):速查 Docker 客户端和服务端的常用命令。 +* [**Dockerfile 最佳实践**](best_practices.md):提供编写高效、安全 Dockerfile 的指导原则。 +* [**如何调试 Docker**](debug.md):介绍 Docker 调试技巧和工具。 +* [**资源链接**](resources.md):推荐更多 Docker 相关的学习资源。 \ No newline at end of file diff --git a/appendix/_images/cmd_logic.dot b/15_appendix/_images/cmd_logic.dot similarity index 100% rename from appendix/_images/cmd_logic.dot rename to 15_appendix/_images/cmd_logic.dot diff --git a/appendix/_images/cmd_logic.dot.bak b/15_appendix/_images/cmd_logic.dot.bak similarity index 100% rename from appendix/_images/cmd_logic.dot.bak rename to 15_appendix/_images/cmd_logic.dot.bak diff --git a/appendix/_images/cmd_logic.graffle/data.plist b/15_appendix/_images/cmd_logic.graffle/data.plist similarity index 100% rename from appendix/_images/cmd_logic.graffle/data.plist rename to 15_appendix/_images/cmd_logic.graffle/data.plist diff --git a/appendix/_images/cmd_logic.graffle/image10.pdf b/15_appendix/_images/cmd_logic.graffle/image10.pdf similarity index 100% rename from appendix/_images/cmd_logic.graffle/image10.pdf rename to 15_appendix/_images/cmd_logic.graffle/image10.pdf diff --git a/appendix/_images/cmd_logic.graffle/image11.pdf b/15_appendix/_images/cmd_logic.graffle/image11.pdf similarity index 100% rename from appendix/_images/cmd_logic.graffle/image11.pdf rename to 15_appendix/_images/cmd_logic.graffle/image11.pdf diff --git a/appendix/_images/cmd_logic.graffle/image12.pdf b/15_appendix/_images/cmd_logic.graffle/image12.pdf similarity index 100% rename from appendix/_images/cmd_logic.graffle/image12.pdf rename to 15_appendix/_images/cmd_logic.graffle/image12.pdf diff --git a/appendix/_images/cmd_logic.graffle/image13.pdf b/15_appendix/_images/cmd_logic.graffle/image13.pdf similarity index 100% rename from appendix/_images/cmd_logic.graffle/image13.pdf rename to 15_appendix/_images/cmd_logic.graffle/image13.pdf diff --git a/appendix/_images/cmd_logic.graffle/image4.pdf b/15_appendix/_images/cmd_logic.graffle/image4.pdf similarity index 100% rename from appendix/_images/cmd_logic.graffle/image4.pdf rename to 15_appendix/_images/cmd_logic.graffle/image4.pdf diff --git a/appendix/_images/cmd_logic.graffle/image5.pdf b/15_appendix/_images/cmd_logic.graffle/image5.pdf similarity index 100% rename from appendix/_images/cmd_logic.graffle/image5.pdf rename to 15_appendix/_images/cmd_logic.graffle/image5.pdf diff --git a/appendix/_images/cmd_logic.graffle/image6.pdf b/15_appendix/_images/cmd_logic.graffle/image6.pdf similarity index 100% rename from appendix/_images/cmd_logic.graffle/image6.pdf rename to 15_appendix/_images/cmd_logic.graffle/image6.pdf diff --git a/appendix/_images/cmd_logic.graffle/image7.pdf b/15_appendix/_images/cmd_logic.graffle/image7.pdf similarity index 100% rename from appendix/_images/cmd_logic.graffle/image7.pdf rename to 15_appendix/_images/cmd_logic.graffle/image7.pdf diff --git a/appendix/_images/cmd_logic.graffle/image9.pdf b/15_appendix/_images/cmd_logic.graffle/image9.pdf similarity index 100% rename from appendix/_images/cmd_logic.graffle/image9.pdf rename to 15_appendix/_images/cmd_logic.graffle/image9.pdf diff --git a/.gitbook/assets/cmd_logic.png b/15_appendix/_images/cmd_logic.png similarity index 100% rename from .gitbook/assets/cmd_logic.png rename to 15_appendix/_images/cmd_logic.png diff --git a/appendix/_images/container_status.dot b/15_appendix/_images/container_status.dot similarity index 100% rename from appendix/_images/container_status.dot rename to 15_appendix/_images/container_status.dot diff --git a/appendix/_images/container_status.png b/15_appendix/_images/container_status.png similarity index 100% rename from appendix/_images/container_status.png rename to 15_appendix/_images/container_status.png diff --git a/appendix/best_practices.md b/15_appendix/best_practices.md similarity index 99% rename from appendix/best_practices.md rename to 15_appendix/best_practices.md index f0959ff..4f680bb 100644 --- a/appendix/best_practices.md +++ b/15_appendix/best_practices.md @@ -14,7 +14,7 @@ ### 使用多阶段构建 -在 `Docker 17.05` 以上版本中,你可以使用 [多阶段构建](../image/multistage-builds.md) 来减少所构建镜像的大小。 +在 `Docker 17.05` 以上版本中,你可以使用 [多阶段构建](../04_image/multistage-builds.md) 来减少所构建镜像的大小。 ### 避免安装不必要的包 diff --git a/appendix/command/README.md b/15_appendix/command/README.md similarity index 100% rename from appendix/command/README.md rename to 15_appendix/command/README.md diff --git a/appendix/command/docker.md b/15_appendix/command/docker.md similarity index 98% rename from appendix/command/docker.md rename to 15_appendix/command/docker.md index c99f675..f8da822 100644 --- a/appendix/command/docker.md +++ b/15_appendix/command/docker.md @@ -64,7 +64,7 @@ ## 一张图总结 Docker 的命令 -![Docker 命令总结](../../.gitbook/assets/cmd_logic.png) +![Docker 命令总结](../../_images/cmd_logic.png) ## 参考 diff --git a/appendix/command/dockerd.md b/15_appendix/command/dockerd.md similarity index 100% rename from appendix/command/dockerd.md rename to 15_appendix/command/dockerd.md diff --git a/15_appendix/debug.md b/15_appendix/debug.md new file mode 100644 index 0000000..ae89bff --- /dev/null +++ b/15_appendix/debug.md @@ -0,0 +1,73 @@ +# 如何调试 Docker + +## 开启 Debug 模式 + +在 dockerd 配置文件 daemon.json(默认位于 /etc/docker/)中添加 + +```json +{ + "debug": true +} +``` + +重启守护进程。 + +```bash +$ sudo kill -SIGHUP $(pidof dockerd) +``` + +此时 dockerd 会在日志中输入更多信息供分析。 + +## 检查内核日志 + +```bash +$ sudo dmesg |grep dockerd +$ sudo dmesg |grep runc +``` + +## Docker 不响应时处理 + +可以杀死 dockerd 进程查看其堆栈调用情况。 + +```bash +$ sudo kill -SIGUSR1 $(pidof dockerd) +``` + +## 重置 Docker 本地数据 + +*注意,本操作会移除所有的 Docker 本地数据,包括镜像和容器等。* + +$ sudo rm -rf /var/lib/docker +``` + +## 常见故障排查 + +### 容器启动失败 + +如果容器启动后立即退出,可以使用 `docker logs` 查看原因。 + +* **Exit Code 1**: 应用程序错误。通常是配置错误或依赖缺失。 +* **Exit Code 137**: OOM (Out Of Memory)。容器内存不足被内核杀掉。 + * 检查宿主机内存。 + * 调整容器内存限制 (`--memory`)。 +* **Exit Code 127**: 命令未找到。可能是 `ENTRYPOINT` 或 `CMD` 指定的命令不存在。 + +### 网络连接问题 + +#### 容器内部无法联网 + +1. 检查 Docker DNS 配置 (`/etc/docker/daemon.json`)。 +2. 检查宿主机防火墙 (iptables/firewalld) 是否拦截了转发。 +3. 容器内测试: `ping 8.8.8.8` (测试连通性), `nslookup google.com` (测试 DNS)。 + +#### 端口映射不通 + +1. 检查容器端口是否正确监听: `netstat -tunlp` (宿主机) 或 `docker exec netstat -tunlp`。 +2. 确认应用监听地址是 `0.0.0.0` 而不是 `127.0.0.1`。 + * 如果应用监听在 `127.0.0.1`,只有容器内部能访问,映射到宿主机外部也无法被外部请求访问。 + +### 镜像拉取失败 + +* **connection refused**: 检查网络或代理设置。 +* **image not found**: 检查镜像名称和 Tag 拼写。 +* **EOF / timeout**: 网络不稳定,尝试配置镜像加速器。 diff --git a/appendix/faq/README.md b/15_appendix/faq/README.md similarity index 100% rename from appendix/faq/README.md rename to 15_appendix/faq/README.md diff --git a/15_appendix/faq/errors.md b/15_appendix/faq/errors.md new file mode 100644 index 0000000..4503a8c --- /dev/null +++ b/15_appendix/faq/errors.md @@ -0,0 +1,13 @@ +# 常见错误速查表 + +| 错误信息 / 现象 | 可能原因 | 解决方案 | +| :--- | :--- | :--- | +| `Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?` | Docker 服务未启动 | Linux: `sudo systemctl start docker`
Mac/Win: 启动 Docker Desktop | +| `permission denied while trying to connect to the Docker daemon socket` | 当前用户不在 `docker` 用户组 | `sudo usermod -aG docker $USER` (需重新登录) | +| `manifest for ... not found: manifest unknown` | 镜像 tag 不存在 | 检查 Docker Hub 该镜像是否存在该 tag,或拼写是否正确 | +| `connection refused` (pull image) | 网络不通或镜像源无法访问 | 检查网络,配置[镜像加速器](../../install/mirror.md) | +| `Bind for 0.0.0.0:8080 failed: port is already allocated` | 端口被占用 | 检查占用端口的进程 (`lsof -i:8080`) 并杀掉,或换个端口映射 (`-p 8081:80`) | +| `exec user process caused "exec format error"` | 架构不匹配 (如在 x86 上跑 ARM 镜像) | 使用 `docker buildx` 构建多架构镜像,或拉取对应架构的镜像 | +| `standard_init_linux.go:211: exec user process caused "no such file or directory"` | 找不到解释器或依赖库 | 检查 `ENTRYPOINT`/`CMD` 脚本开头的 shebang (`#!/bin/sh` vs `#!/bin/bash`),或确认二进制文件是否依赖缺失 (Alpine 常见缺少 glibc) | +| `iptables: No chain/target/match by that name` | 防火墙规则缺失或冲突 | 重启 Docker 服务重置 iptables 链: `sudo systemctl restart docker` | +| 容器内无法访问外网 | DNS 配置或转发问题 | 检查 `/etc/docker/daemon.json` 中的 DNS 配置 | diff --git a/appendix/repo/README.md b/15_appendix/repo/README.md similarity index 100% rename from appendix/repo/README.md rename to 15_appendix/repo/README.md diff --git a/appendix/repo/centos.md b/15_appendix/repo/centos.md similarity index 100% rename from appendix/repo/centos.md rename to 15_appendix/repo/centos.md diff --git a/appendix/repo/minio.md b/15_appendix/repo/minio.md similarity index 100% rename from appendix/repo/minio.md rename to 15_appendix/repo/minio.md diff --git a/appendix/repo/mongodb.md b/15_appendix/repo/mongodb.md similarity index 100% rename from appendix/repo/mongodb.md rename to 15_appendix/repo/mongodb.md diff --git a/appendix/repo/mysql.md b/15_appendix/repo/mysql.md similarity index 100% rename from appendix/repo/mysql.md rename to 15_appendix/repo/mysql.md diff --git a/appendix/repo/nginx.md b/15_appendix/repo/nginx.md similarity index 100% rename from appendix/repo/nginx.md rename to 15_appendix/repo/nginx.md diff --git a/appendix/repo/nodejs.md b/15_appendix/repo/nodejs.md similarity index 100% rename from appendix/repo/nodejs.md rename to 15_appendix/repo/nodejs.md diff --git a/appendix/repo/php.md b/15_appendix/repo/php.md similarity index 100% rename from appendix/repo/php.md rename to 15_appendix/repo/php.md diff --git a/appendix/repo/redis.md b/15_appendix/repo/redis.md similarity index 100% rename from appendix/repo/redis.md rename to 15_appendix/repo/redis.md diff --git a/appendix/repo/ubuntu.md b/15_appendix/repo/ubuntu.md similarity index 100% rename from appendix/repo/ubuntu.md rename to 15_appendix/repo/ubuntu.md diff --git a/appendix/repo/wordpress.md b/15_appendix/repo/wordpress.md similarity index 100% rename from appendix/repo/wordpress.md rename to 15_appendix/repo/wordpress.md diff --git a/appendix/resources.md b/15_appendix/resources.md similarity index 100% rename from appendix/resources.md rename to 15_appendix/resources.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 8be505f..2ab6ba8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 修订记录 +* 1.5.0 2026-02-05 + * 全面重构章节目录结构 (01-15) + * 支持 Docker Engine v30.x + * 优化文档图片引用路径 + * 1.4.0 2026-01-11 * 全面支持 Docker Engine v29 新版本 * 更新 Docker Compose 至 v2.40.x diff --git a/README.md b/README.md index 4ff53a1..589b958 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![](https://img.shields.io/github/stars/yeasy/docker_practice.svg?style=social&label=Stars)](https://github.com/yeasy/docker_practice) [![](https://img.shields.io/github/release/yeasy/docker_practice/all.svg)](https://github.com/yeasy/docker_practice/releases) [![](https://img.shields.io/badge/Based-Docker%20CE%20v30.x-blue.svg)](https://github.com/docker/docker-ce) [![](https://img.shields.io/badge/Docker%20%E6%8A%80%E6%9C%AF%E5%85%A5%E9%97%A8%E4%B8%8E%E5%AE%9E%E6%88%98-jd.com-red.svg)][1] -**v1.4.6** +**v1.5.0** [Docker](https://www.docker.com) 是个划时代的开源项目,它彻底释放了计算虚拟化的威力,极大提高了应用的维护效率,降低了云计算应用开发的成本!使用 Docker,可以让应用的部署、测试和分发都变得前所未有的高效和轻松! @@ -12,10 +12,10 @@ ## 内容特色 -* **系统全面**:前六章为基础内容,帮助深入理解 Docker 的基本概念(镜像、容器、仓库)和核心操作。 -* **进阶实战**:7 ~ 9 章涵盖数据管理、网络配置、Dockerfile 最佳实践等高级操作。 -* **生态深度**:10 ~ 12 章介绍 Kubernetes、Etcd 等容器生态核心项目。 -* **安全实现**:13、14 章深入讨论 Docker 安全机制与底层实现技术。 +* **入门基础**:前六章为基础内容,帮助深入理解 Docker 的基本概念(镜像、容器、仓库)和核心操作。 +* **进阶应用**:7 ~ 10 章涵盖数据管理、网络配置、Buildx、Compose、运维管理等高级操作。 +* **深入原理**:11 ~ 13 章介绍容器编排(Kubernetes、Etcd)、容器生态、底层实现技术。 +* **实战扩展**:14 ~ 15 章展示操作系统、CI/CD等典型应用场景和实践案例,以及工具参考。 * **广泛扩展**:涵盖 Fedora CoreOS、容器云等热门开源项目,并展示典型的应用场景和实践案例。 ## 阅读方式 diff --git a/SUMMARY.md b/SUMMARY.md index 1e38119..77162bd 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -3,151 +3,180 @@ * [前言](README.md) * [修订记录](CHANGELOG.md) * [如何贡献](CONTRIBUTING.md) -* [Docker 简介](introduction/README.md) - * [什么是 Docker](introduction/what.md) - * [为什么要用 Docker](introduction/why.md) -* [基本概念](basic_concept/README.md) - * [镜像](basic_concept/image.md) - * [容器](basic_concept/container.md) - * [仓库](basic_concept/repository.md) -* [安装 Docker](install/README.md) - * [Ubuntu](install/ubuntu.md) - * [Debian](install/debian.md) - * [Fedora](install/fedora.md) - * [CentOS](install/centos.md) - * [Raspberry Pi](install/raspberry-pi.md) - * [Linux 离线安装](install/offline.md) - * [macOS](install/mac.md) - * [Windows 10/11](install/windows.md) - * [镜像加速器](install/mirror.md) - * [开启实验特性](install/experimental.md) -* [使用镜像](image/README.md) - * [获取镜像](image/pull.md) - * [列出镜像](image/list.md) - * [删除本地镜像](image/rm.md) - * [利用 commit 理解镜像构成](image/commit.md) - * [使用 Dockerfile 定制镜像](image/build.md) - * [Dockerfile 指令详解](image/dockerfile/README.md) - * [RUN 执行命令](image/dockerfile/run.md) - * [COPY 复制文件](image/dockerfile/copy.md) - * [ADD 更高级的复制文件](image/dockerfile/add.md) - * [CMD 容器启动命令](image/dockerfile/cmd.md) - * [ENTRYPOINT 入口点](image/dockerfile/entrypoint.md) - * [ENV 设置环境变量](image/dockerfile/env.md) - * [ARG 构建参数](image/dockerfile/arg.md) - * [VOLUME 定义匿名卷](image/dockerfile/volume.md) - * [EXPOSE 暴露端口](image/dockerfile/expose.md) - * [WORKDIR 指定工作目录](image/dockerfile/workdir.md) - * [USER 指定当前用户](image/dockerfile/user.md) - * [HEALTHCHECK 健康检查](image/dockerfile/healthcheck.md) - * [ONBUILD 为他人作嫁衣裳](image/dockerfile/onbuild.md) - * [LABEL 为镜像添加元数据](image/dockerfile/label.md) - * [SHELL 指令](image/dockerfile/shell.md) - * [参考文档](image/dockerfile/references.md) - * [Dockerfile 多阶段构建](image/multistage-builds/README.md) - * [实战多阶段构建 Laravel 镜像](image/multistage-builds/laravel.md) - * [其它制作镜像的方式](image/other.md) - * [实现原理](image/internal.md) -* [操作容器](container/README.md) - * [启动](container/run.md) - * [守护态运行](container/daemon.md) - * [终止](container/stop.md) - * [进入容器](container/attach_exec.md) - * [导出和导入](container/import_export.md) - * [删除](container/rm.md) -* [访问仓库](repository/README.md) - * [Docker Hub](repository/dockerhub.md) - * [私有仓库](repository/registry.md) - * [私有仓库高级配置](repository/registry_auth.md) - * [Nexus 3](repository/nexus3_registry.md) -* [数据管理](data_management/README.md) - * [数据卷](data_management/volume.md) - * [挂载主机目录](data_management/bind-mounts.md) -* [网络配置](network/README.md) - * [配置 DNS](network/dns.md) - * [外部访问容器](network/port_mapping.md) -* [Docker Buildx](buildx/README.md) - * [BuildKit](buildx/buildkit.md) - * [使用 buildx 构建镜像](buildx/buildx.md) - * [使用 buildx 构建多种系统架构支持的 Docker 镜像](buildx/multi-arch-images.md) -* [Docker Compose](compose/README.md) - * [简介](compose/introduction.md) - * [安装与卸载](compose/install.md) - * [使用](compose/usage.md) - * [命令说明](compose/commands.md) - * [Compose 模板文件](compose/compose_file.md) - * [实战 Django](compose/django.md) - * [实战 Rails](compose/rails.md) - * [实战 WordPress](compose/wordpress.md) - * [实战 LNMP](compose/lnmp.md) -* [安全](security/README.md) - * [内核命名空间](security/kernel_ns.md) - * [控制组](security/control_group.md) - * [服务端防护](security/daemon_sec.md) - * [内核能力机制](security/kernel_capability.md) - * [其它安全特性](security/other_feature.md) - * [总结](security/summary.md) -* [底层实现](underly/README.md) - * [基本架构](underly/arch.md) - * [命名空间](underly/namespace.md) - * [控制组](underly/cgroups.md) - * [联合文件系统](underly/ufs.md) - * [容器格式](underly/container_format.md) - * [网络](underly/network.md) -* [Etcd 项目](etcd/README.md) - * [简介](etcd/intro.md) - * [安装](etcd/install.md) - * [集群](etcd/cluster.md) - * [使用 etcdctl](etcd/etcdctl.md) -* [Fedora CoreOS](coreos/README.md) - * [简介](coreos/intro.md) - * [安装](coreos/install.md) -* [Kubernetes - 开源容器编排引擎](kubernetes/README.md) - * [简介](kubernetes/intro.md) - * [基本概念](kubernetes/concepts.md) - * [架构设计](kubernetes/design.md) -* [部署 Kubernetes](kubernetes/setup/README.md) - * [使用 kubeadm 部署 kubernetes(CRI 使用 containerd)](kubernetes/setup/kubeadm.md) - * [在 Docker Desktop 使用](kubernetes/setup/docker-desktop.md) - * [一步步部署 kubernetes 集群](kubernetes/setup/systemd.md) - * [部署 Dashboard](kubernetes/setup/dashboard.md) -* [Kubernetes 命令行 kubectl](kubernetes/kubectl/README.md) -* [容器与云计算](cloud/README.md) - * [简介](cloud/intro.md) - * [腾讯云](cloud/tencentCloud.md) - * [阿里云](cloud/alicloud.md) - * [亚马逊云](cloud/aws.md) - * [小结](cloud/summary.md) -* [实战案例 - 操作系统](cases/os/README.md) - * [Busybox](cases/os/busybox.md) - * [Alpine](cases/os/alpine.md) - * [Debian Ubuntu](cases/os/debian.md) - * [CentOS Fedora](cases/os/centos.md) - * [本章小结](cases/os/summary.md) -* [实战案例 - CI/CD](cases/ci/README.md) - * [GitHub Actions](cases/ci/actions/README.md) - * [Drone](cases/ci/drone/README.md) - * [部署 Drone](cases/ci/drone/install.md) -* [在 IDE 中使用 Docker](ide/README.md) - * [VS Code](ide/vsCode.md) -* [podman - 下一代 Linux 容器工具](podman/README.md) -* [附录](appendix/README.md) - * [附录一:常见问题总结](appendix/faq/README.md) - * [附录二:热门镜像介绍](appendix/repo/README.md) - * [Ubuntu](appendix/repo/ubuntu.md) - * [CentOS](appendix/repo/centos.md) - * [Nginx](appendix/repo/nginx.md) - * [PHP](appendix/repo/php.md) - * [Node.js](appendix/repo/nodejs.md) - * [MySQL](appendix/repo/mysql.md) - * [WordPress](appendix/repo/wordpress.md) - * [MongoDB](appendix/repo/mongodb.md) - * [Redis](appendix/repo/redis.md) - * [Minio](appendix/repo/minio.md) - * [附录三:Docker 命令查询](appendix/command/README.md) - * [客户端命令 - docker](appendix/command/docker.md) - * [服务端命令 - dockerd](appendix/command/dockerd.md) - * [附录四:Dockerfile 最佳实践](appendix/best_practices.md) - * [附录五:如何调试 Docker](appendix/debug.md) - * [附录六:资源链接](appendix/resources.md) +## 第一部分: 入门篇 + +* [第一章 Docker 简介](01_introduction/README.md) + * [快速上手](01_introduction/quickstart.md) + * [什么是 Docker](01_introduction/what.md) + * [为什么要用 Docker](01_introduction/why.md) +* [第二章 基本概念](02_basic_concept/README.md) + * [镜像](02_basic_concept/image.md) + * [容器](02_basic_concept/container.md) + * [仓库](02_basic_concept/repository.md) +* [第三章 安装 Docker](03_install/README.md) + * [Ubuntu](03_install/ubuntu.md) + * [Debian](03_install/debian.md) + * [Fedora](03_install/fedora.md) + * [CentOS](03_install/centos.md) + * [Raspberry Pi](03_install/raspberry-pi.md) + * [Linux 离线安装](03_install/offline.md) + * [macOS](03_install/mac.md) + * [Windows 10/11](03_install/windows.md) + * [镜像加速器](03_install/mirror.md) + * [开启实验特性](03_install/experimental.md) +* [第四章 使用镜像](04_image/README.md) + * [获取镜像](04_image/pull.md) + * [列出镜像](04_image/list.md) + * [删除本地镜像](04_image/rm.md) + * [利用 commit 理解镜像构成](04_image/commit.md) + * [使用 Dockerfile 定制镜像](04_image/build.md) + * [Dockerfile 指令详解](04_image/dockerfile/README.md) + * [RUN 执行命令](04_image/dockerfile/run.md) + * [COPY 复制文件](04_image/dockerfile/copy.md) + * [ADD 更高级的复制文件](04_image/dockerfile/add.md) + * [CMD 容器启动命令](04_image/dockerfile/cmd.md) + * [ENTRYPOINT 入口点](04_image/dockerfile/entrypoint.md) + * [ENV 设置环境变量](04_image/dockerfile/env.md) + * [ARG 构建参数](04_image/dockerfile/arg.md) + * [VOLUME 定义匿名卷](04_image/dockerfile/volume.md) + * [EXPOSE 暴露端口](04_image/dockerfile/expose.md) + * [WORKDIR 指定工作目录](04_image/dockerfile/workdir.md) + * [USER 指定当前用户](04_image/dockerfile/user.md) + * [HEALTHCHECK 健康检查](04_image/dockerfile/healthcheck.md) + * [ONBUILD 为他人作嫁衣裳](04_image/dockerfile/onbuild.md) + * [LABEL 为镜像添加元数据](04_image/dockerfile/label.md) + * [SHELL 指令](04_image/dockerfile/shell.md) + * [参考文档](04_image/dockerfile/references.md) + * [Dockerfile 多阶段构建](04_image/multistage-builds/README.md) + * [实战多阶段构建 Laravel 镜像](04_image/multistage-builds/laravel.md) + * [其它制作镜像的方式](04_image/other.md) + * [实现原理](04_image/internal.md) +* [第五章 操作容器](05_container/README.md) + * [启动](05_container/run.md) + * [守护态运行](05_container/daemon.md) + * [终止](05_container/stop.md) + * [进入容器](05_container/attach_exec.md) + * [导出和导入](05_container/import_export.md) + * [删除](05_container/rm.md) +* [第六章 访问仓库](06_repository/README.md) + * [Docker Hub](06_repository/dockerhub.md) + * [私有仓库](06_repository/registry.md) + * [私有仓库高级配置](06_repository/registry_auth.md) + * [Nexus 3](06_repository/nexus3_registry.md) + +## 第二部分: 进阶篇 + +* [第七章 数据与网络管理](07_data_network/README.md) + * [数据管理](07_data_network/data/README.md) + * [数据卷](07_data_network/data/volume.md) + * [挂载主机目录](07_data_network/data/bind-mounts.md) + * [网络配置](07_data_network/network/README.md) + * [配置 DNS](07_data_network/network/dns.md) + * [外部访问容器](07_data_network/network/port_mapping.md) +* [第八章 Docker Buildx](08_buildx/README.md) + * [BuildKit](08_buildx/buildkit.md) + * [使用 buildx 构建镜像](08_buildx/buildx.md) + * [使用 buildx 构建多种系统架构支持的 Docker 镜像](08_buildx/multi-arch-images.md) +* [第九章 Docker Compose](09_compose/README.md) + * [简介](09_compose/introduction.md) + * [安装与卸载](09_compose/install.md) + * [使用](09_compose/usage.md) + * [命令说明](09_compose/commands.md) + * [Compose 模板文件](09_compose/compose_file.md) + * [实战 Django](09_compose/django.md) + * [实战 Rails](09_compose/rails.md) + * [实战 WordPress](09_compose/wordpress.md) + * [实战 LNMP](09_compose/lnmp.md) +* [第十章 运维管理](10_ops/README.md) + * [容器监控](10_ops/monitor/README.md) + * [Prometheus](10_ops/monitor/prometheus.md) + * [日志管理](10_ops/logs/README.md) + * [ELK 套件](10_ops/logs/elk.md) + * [安全](10_ops/security/README.md) + * [内核命名空间](10_ops/security/kernel_ns.md) + * [控制组](10_ops/security/control_group.md) + * [服务端防护](10_ops/security/daemon_sec.md) + * [内核能力机制](10_ops/security/kernel_capability.md) + * [其它安全特性](10_ops/security/other_feature.md) + * [总结](10_ops/security/summary.md) + +## 第三部分: 深入篇 + +* [第十一章 容器编排](11_orchestration/README.md) + * [Etcd 项目](11_orchestration/etcd/README.md) + * [简介](11_orchestration/etcd/intro.md) + * [安装](11_orchestration/etcd/install.md) + * [集群](11_orchestration/etcd/cluster.md) + * [使用 etcdctl](11_orchestration/etcd/etcdctl.md) + * [Kubernetes - 开源容器编排引擎](11_orchestration/kubernetes/README.md) + * [简介](11_orchestration/kubernetes/intro.md) + * [基本概念](11_orchestration/kubernetes/concepts.md) + * [架构设计](11_orchestration/kubernetes/design.md) + * [高级特性](11_orchestration/kubernetes/advanced.md) + * [实战练习](11_orchestration/kubernetes/practice.md) + * [部署 Kubernetes](11_orchestration/setup/README.md) + * [使用 kubeadm 部署 kubernetes(CRI 使用 containerd)](11_orchestration/setup/kubeadm.md) + * [使用 kubeadm 部署 kubernetes(CRI 使用 Docker)](11_orchestration/setup/kubeadm-docker.md) + * [在 Docker Desktop 使用](11_orchestration/setup/docker-desktop.md) + * [Kind - Kubernetes IN Docker](11_orchestration/setup/kind.md) + * [K3s - 轻量级 Kubernetes](11_orchestration/setup/k3s.md) + * [一步步部署 kubernetes 集群](11_orchestration/setup/systemd.md) + * [部署 Dashboard](11_orchestration/setup/dashboard.md) + * [Kubernetes 命令行 kubectl](11_orchestration/kubectl/README.md) +* [第十二章 容器生态](12_ecosystem/README.md) + * [Fedora CoreOS](12_ecosystem/coreos/README.md) + * [简介](12_ecosystem/coreos/intro.md) + * [安装](12_ecosystem/coreos/install.md) + * [容器与云计算](12_ecosystem/cloud/README.md) + * [简介](12_ecosystem/cloud/intro.md) + * [腾讯云](12_ecosystem/cloud/tencentCloud.md) + * [阿里云](12_ecosystem/cloud/alicloud.md) + * [亚马逊云](12_ecosystem/cloud/aws.md) + * [小结](12_ecosystem/cloud/summary.md) + * [多云部署策略](12_ecosystem/cloud/multicloud.md) + * [podman - 下一代 Linux 容器工具](12_ecosystem/podman/README.md) +* [第十三章 底层实现](13_implementation/README.md) + * [基本架构](13_implementation/arch.md) + * [命名空间](13_implementation/namespace.md) + * [控制组](13_implementation/cgroups.md) + * [联合文件系统](13_implementation/ufs.md) + * [容器格式](13_implementation/container_format.md) + * [网络](13_implementation/network.md) + +## 第四部分: 实战篇 + +* [第十四章 实战案例](14_cases/README.md) + * [实战案例 - 操作系统](14_cases/os/README.md) + * [Busybox](14_cases/os/busybox.md) + * [Alpine](14_cases/os/alpine.md) + * [Debian Ubuntu](14_cases/os/debian.md) + * [CentOS Fedora](14_cases/os/centos.md) + * [本章小结](14_cases/os/summary.md) + * [实战案例 - CI/CD](14_cases/ci/README.md) + * [DevOps 完整工作流](14_cases/ci/devops_workflow.md) + * [GitHub Actions](14_cases/ci/actions/README.md) + * [Drone](14_cases/ci/drone/README.md) + * [部署 Drone](14_cases/ci/drone/install.md) + * [在 IDE 中使用 Docker](14_cases/ide/README.md) + * [VS Code](14_cases/ide/vsCode.md) +* [第十五章 附录](15_appendix/README.md) + * [附录一:常见问题总结](15_appendix/faq/README.md) + * [常见错误速查表](15_appendix/faq/errors.md) + * [附录二:热门镜像介绍](15_appendix/repo/README.md) + * [Ubuntu](15_appendix/repo/ubuntu.md) + * [CentOS](15_appendix/repo/centos.md) + * [Nginx](15_appendix/repo/nginx.md) + * [PHP](15_appendix/repo/php.md) + * [Node.js](15_appendix/repo/nodejs.md) + * [MySQL](15_appendix/repo/mysql.md) + * [WordPress](15_appendix/repo/wordpress.md) + * [MongoDB](15_appendix/repo/mongodb.md) + * [Redis](15_appendix/repo/redis.md) + * [Minio](15_appendix/repo/minio.md) + * [附录三:Docker 命令查询](15_appendix/command/README.md) + * [客户端命令 - docker](15_appendix/command/docker.md) + * [服务端命令 - dockerd](15_appendix/command/dockerd.md) + * [附录四:Dockerfile 最佳实践](15_appendix/best_practices.md) + * [附录五:如何调试 Docker](15_appendix/debug.md) + * [附录六:资源链接](15_appendix/resources.md) diff --git a/cloud/_images/ECS.jpg b/_images/ECS.jpg similarity index 100% rename from cloud/_images/ECS.jpg rename to _images/ECS.jpg diff --git a/cloud/_images/aliyun-logo.png b/_images/aliyun-logo.png similarity index 100% rename from cloud/_images/aliyun-logo.png rename to _images/aliyun-logo.png diff --git a/cases/os/_images/alpinelinux-logo.png b/_images/alpinelinux-logo.png similarity index 100% rename from cases/os/_images/alpinelinux-logo.png rename to _images/alpinelinux-logo.png diff --git a/cloud/_images/aws-logo.jpg b/_images/aws-logo.jpg similarity index 100% rename from cloud/_images/aws-logo.jpg rename to _images/aws-logo.jpg diff --git a/cases/os/_images/busybox-logo.png b/_images/busybox-logo.png similarity index 100% rename from cases/os/_images/busybox-logo.png rename to _images/busybox-logo.png diff --git a/cases/os/_images/centos-logo.png b/_images/centos-logo.png similarity index 100% rename from cases/os/_images/centos-logo.png rename to _images/centos-logo.png diff --git a/appendix/_images/cmd_logic.png b/_images/cmd_logic.png similarity index 100% rename from appendix/_images/cmd_logic.png rename to _images/cmd_logic.png diff --git a/cases/os/_images/debian-logo.png b/_images/debian-logo.png similarity index 100% rename from cases/os/_images/debian-logo.png rename to _images/debian-logo.png diff --git a/introduction/_images/docker-on-linux.png b/_images/docker-on-linux.png similarity index 100% rename from introduction/_images/docker-on-linux.png rename to _images/docker-on-linux.png diff --git a/.gitbook/assets/docker.png b/_images/docker.png similarity index 100% rename from .gitbook/assets/docker.png rename to _images/docker.png diff --git a/underly/_images/docker_arch.png b/_images/docker_arch.png similarity index 100% rename from underly/_images/docker_arch.png rename to _images/docker_arch.png diff --git a/cases/ci/drone/_images/drone-build.png b/_images/drone-build.png similarity index 100% rename from cases/ci/drone/_images/drone-build.png rename to _images/drone-build.png diff --git a/etcd/_images/etcd_logo.png b/_images/etcd_logo.png similarity index 100% rename from etcd/_images/etcd_logo.png rename to _images/etcd_logo.png diff --git a/cases/os/_images/fedora-logo.png b/_images/fedora-logo.png similarity index 100% rename from cases/os/_images/fedora-logo.png rename to _images/fedora-logo.png diff --git a/install/_images/image-20200412202617411.png b/_images/image-20200412202617411.png similarity index 100% rename from install/_images/image-20200412202617411.png rename to _images/image-20200412202617411.png diff --git a/image/_images/images-create-nginx-docker.png b/_images/images-create-nginx-docker.png similarity index 100% rename from image/_images/images-create-nginx-docker.png rename to _images/images-create-nginx-docker.png diff --git a/image/_images/images-mac-example-nginx.png b/_images/images-mac-example-nginx.png similarity index 100% rename from image/_images/images-mac-example-nginx.png rename to _images/images-mac-example-nginx.png diff --git a/install/_images/install-mac-apps.png b/_images/install-mac-apps.png similarity index 100% rename from install/_images/install-mac-apps.png rename to _images/install-mac-apps.png diff --git a/install/_images/install-mac-dmg.png b/_images/install-mac-dmg.png similarity index 100% rename from install/_images/install-mac-dmg.png rename to _images/install-mac-dmg.png diff --git a/install/_images/install-mac-example-nginx.png b/_images/install-mac-example-nginx.png similarity index 100% rename from install/_images/install-mac-example-nginx.png rename to _images/install-mac-example-nginx.png diff --git a/install/_images/install-mac-menu.png b/_images/install-mac-menu.png similarity index 100% rename from install/_images/install-mac-menu.png rename to _images/install-mac-menu.png diff --git a/install/_images/install-mac-menubar.png b/_images/install-mac-menubar.png similarity index 100% rename from install/_images/install-mac-menubar.png rename to _images/install-mac-menubar.png diff --git a/install/_images/install-win-docker-app-search.png b/_images/install-win-docker-app-search.png similarity index 100% rename from install/_images/install-win-docker-app-search.png rename to _images/install-win-docker-app-search.png diff --git a/install/_images/install-win-taskbar-circle.png b/_images/install-win-taskbar-circle.png similarity index 100% rename from install/_images/install-win-taskbar-circle.png rename to _images/install-win-taskbar-circle.png diff --git a/kubernetes/_images/k8s_architecture.png b/_images/k8s_architecture.png similarity index 100% rename from kubernetes/_images/k8s_architecture.png rename to _images/k8s_architecture.png diff --git a/kubernetes/_images/kube-proxy.png b/_images/kube-proxy.png similarity index 100% rename from kubernetes/_images/kube-proxy.png rename to _images/kube-proxy.png diff --git a/kubernetes/_images/kubernetes_design.jpg b/_images/kubernetes_design.jpg similarity index 100% rename from kubernetes/_images/kubernetes_design.jpg rename to _images/kubernetes_design.jpg diff --git a/kubernetes/_images/kubernetes_logo.png b/_images/kubernetes_logo.png similarity index 100% rename from kubernetes/_images/kubernetes_logo.png rename to _images/kubernetes_logo.png diff --git a/.gitbook/assets/network.png b/_images/network.png similarity index 100% rename from .gitbook/assets/network.png rename to _images/network.png diff --git a/cloud/_images/qcloud-logo.jpg b/_images/qcloud-logo.jpg similarity index 100% rename from cloud/_images/qcloud-logo.jpg rename to _images/qcloud-logo.jpg diff --git a/data_management/_images/types-of-mounts.png b/_images/types-of-mounts.png similarity index 100% rename from data_management/_images/types-of-mounts.png rename to _images/types-of-mounts.png diff --git a/cases/os/_images/ubuntu-logo.jpg b/_images/ubuntu-logo.jpg similarity index 100% rename from cases/os/_images/ubuntu-logo.jpg rename to _images/ubuntu-logo.jpg diff --git a/.gitbook/assets/virtualization.png b/_images/virtualization.png similarity index 100% rename from .gitbook/assets/virtualization.png rename to _images/virtualization.png diff --git a/.gitbook/assets/wordpress.png b/_images/wordpress.png similarity index 100% rename from .gitbook/assets/wordpress.png rename to _images/wordpress.png diff --git a/appendix/README.md b/appendix/README.md deleted file mode 100644 index f33bdc5..0000000 --- a/appendix/README.md +++ /dev/null @@ -1 +0,0 @@ -# 附录 \ No newline at end of file diff --git a/appendix/debug.md b/appendix/debug.md deleted file mode 100644 index 90e06cd..0000000 --- a/appendix/debug.md +++ /dev/null @@ -1,42 +0,0 @@ -# 如何调试 Docker - -## 开启 Debug 模式 - -在 dockerd 配置文件 daemon.json(默认位于 /etc/docker/)中添加 - -```json -{ - "debug": true -} -``` - -重启守护进程。 - -```bash -$ sudo kill -SIGHUP $(pidof dockerd) -``` - -此时 dockerd 会在日志中输入更多信息供分析。 - -## 检查内核日志 - -```bash -$ sudo dmesg |grep dockerd -$ sudo dmesg |grep runc -``` - -## Docker 不响应时处理 - -可以杀死 dockerd 进程查看其堆栈调用情况。 - -```bash -$ sudo kill -SIGUSR1 $(pidof dockerd) -``` - -## 重置 Docker 本地数据 - -*注意,本操作会移除所有的 Docker 本地数据,包括镜像和容器等。* - -```bash -$ sudo rm -rf /var/lib/docker -``` diff --git a/book.json b/book.json index 95d0b67..d31db4d 100644 --- a/book.json +++ b/book.json @@ -33,5 +33,19 @@ "minHeaderCount": "2", "minHeaderDeep": "2" } + }, + "pdf": { + "pageNumbers": true, + "fontSize": 12, + "fontFamily": "Arial", + "paperSize": "a4", + "chapterMark": "pagebreak", + "pageBreaksBefore": "/", + "margin": { + "right": 62, + "left": 62, + "top": 56, + "bottom": 56 + } } -} +} \ No newline at end of file diff --git a/cases/ci/drone/demo/README.md b/cases/ci/drone/demo/README.md deleted file mode 100644 index 7ab9812..0000000 --- a/cases/ci/drone/demo/README.md +++ /dev/null @@ -1 +0,0 @@ -# Drone Demo diff --git a/introduction/_images/docker.png b/introduction/_images/docker.png deleted file mode 100644 index 5c1a41d..0000000 Binary files a/introduction/_images/docker.png and /dev/null differ diff --git a/introduction/_images/virtualization.png b/introduction/_images/virtualization.png deleted file mode 100644 index 6e94771..0000000 Binary files a/introduction/_images/virtualization.png and /dev/null differ diff --git a/kubernetes/advanced.md b/kubernetes/advanced.md deleted file mode 100644 index e69de29..0000000 diff --git a/kubernetes/practice.md b/kubernetes/practice.md deleted file mode 100644 index e69de29..0000000 diff --git a/kubernetes/setup/k3s.md b/kubernetes/setup/k3s.md deleted file mode 100644 index e69de29..0000000 diff --git a/kubernetes/setup/kind.md b/kubernetes/setup/kind.md deleted file mode 100644 index e69de29..0000000