Release v1.5.0: Restructure chapters and update for Docker v30.x

This commit is contained in:
Baohua Yang
2026-02-04 22:12:38 -08:00
parent b4b0d4160a
commit fdb879dcf2
304 changed files with 1314 additions and 364 deletions

View File

@@ -0,0 +1,65 @@
# 快速上手 (5分钟)
本节将通过一个简单的 Web 应用例子带你快速体验 Docker 的核心流程构建镜像运行容器
## 1. 准备代码
创建一个名为 `hello-docker` 的文件夹并在其中创建一个 `index.html` 文件
```html
<h1>Hello, Docker!</h1>
```
## 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 <CONTAINER_ID>
# 删除容器
$ docker rm <CONTAINER_ID>
```
恭喜你已经完成了第一次 Docker 实战接下来请阅读 [Docker 核心概念](../02_basic_concept/README.md) 做深入了解