Skip to content

Commit 49d9c6d

Browse files
committed
feat: Add Docker commands
1 parent 2945932 commit 49d9c6d

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

docs/.vitepress/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ function sidebarOthers()
118118
{text: "git 别名", link: "/others/git/bash-alias"},
119119
{text: "在网页上启用设计模式", link: "/others/enable-design-mode-on-the-document"},
120120
{text: "SSH 端口转发",link: "/others/ssh-port-forwarding" },
121+
{text: "Docker 命令", link: "/others/docker-commands-essentials"}
121122
]
122123
}
123124
];
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Docker 命令
2+
3+
## 版本和信息
4+
5+
| 命令 | 说明 |
6+
|--------------------|----------|
7+
| `docker --version` | Docker版本 |
8+
| `docker info` | Docker信息 |
9+
10+
## 容器 Container
11+
12+
| 命令 | 说明 |
13+
|-------------------------------------------|--------------|
14+
| `docekr stats` | 容器资源使用情况 |
15+
| `docker ps` | 查看运行中的容器 |
16+
| `docker ps -a` | 查看所有容器 |
17+
| `docker run <image>` | 从镜像运行容器 |
18+
| `docker run -d <image>` | 从镜像运行容器(后台) |
19+
| `docker run --name ‹name> <image>` | 从镜像运行容器并命名 |
20+
| `docker stop <container>` | 停止容器 |
21+
| `docker start <container>` | 启动容器 |
22+
| `docker restart <container>` | 重启容器 |
23+
| `docker rm <container>` | 删除容器 |
24+
| `docker exec -it <container> /bin/bash` | 进入容器 |
25+
| `docker logs <container>` | 查看容器日志 |
26+
| `docker top <container>` | 查看容器进程 |
27+
| `docker inspect <container>` | 查看容器详细信息 |
28+
| `docker cp <container>:<path> <path>` | 从容器复制文件到主机 |
29+
| `docker cp <path> <container>:<path>` | 从主机复制文件到容器 |
30+
| `docker commit <container> <image>` | 从容器创建镜像 |
31+
| `docker export <container> -o <file.tar>` | 导出容器为 tar 文件 |
32+
33+
## 镜像 Images
34+
35+
| 命令 | 说明 |
36+
|-----------------------------------------|-------------------|
37+
| `docker images` | 查看所有镜像 |
38+
| `docker pull <image>` | 从 Docker Hub 拉取镜像 |
39+
| `docker push <name>:<tag>` | 推送镜像到 Docker Hub |
40+
| `docker rmi <image>` | 删除镜像 |
41+
| `docker build -t <name>:<tag> <path>` | 从 Dockerfile 构建镜像 |
42+
| `docker tag <image> <new_name>:<tag>` | 使用新名称或版本标记镜像 |
43+
| `docker save <image> -o <path>` | 保存镜像到文件 |
44+
| `docker load -i <path>` | 从文件加载镜像 |
45+
| `docker inspect <image>` | 查看镜像详细信息 |
46+
| `docker import <file.tar> <image_name>` | 导入 tar 文件为镜像 |
47+
48+
## 网络 Network
49+
50+
| 命令 | 说明 |
51+
|-----------------------------------------------------------|------------|
52+
| `docker network ls` | 查看所有网络 |
53+
| `docker network create <name>` | 创建网络 |
54+
| `docker network inspect <network>` | 查看网络详细信息 |
55+
| `docker network rm <network>` | 删除网络 |
56+
| `docker network connect <network> <container>` | 连接容器到网络 |
57+
| `docker network disconnect <network> <container>` | 从网络断开容器 |
58+
| `docker network disconnect --force <network> <container>` | 强制从网络断开容器 |
59+
| `docker network prune` | 删除所有未使用的网络 |
60+
61+
## 卷 Volumes
62+
63+
| 命令 | 说明 |
64+
|----------------------------------------|-----------|
65+
| `docker volume ls` | 查看所有卷 |
66+
| `docker volume create <name>` | 创建卷 |
67+
| `docker volume inspect <volume>` | 查看卷详细信息 |
68+
| `docker volume rm <volume>` | 删除卷 |
69+
| `docker volume prune` | 删除所有未使用的卷 |
70+
| `docker run -v <volume>:/path <image>` | 在容器中挂载卷 |
71+
| `docker volume mount <volume>` | 挂载卷 |
72+
| `docker volume unmount <volume>` | 卸载卷 |
73+
| `docker volume update <volume>` | 更新卷 |
74+
75+
## 日志 Logs
76+
77+
| 命令 | 说明 |
78+
|-------------------------------------------|-------------|
79+
| `docker logs <container>` | 查看容器日志 |
80+
| `docker logs -f <container>` | 查看容器日志并实时更新 |
81+
| `docker logs --tail <number> <container>` | 查看容器日志的最后几行 |
82+
83+
## 清理 Docker
84+
85+
| 命令 | 说明 |
86+
|-----------------------------|----------------------|
87+
| `docker system prune` | 清理未使用的镜像、容器、卷和网络 |
88+
| `docker system prune -a` | 清理所有未使用的镜像、容器、卷和网络 |
89+
| `docker system prune -f` | 强制清理未使用的镜像、容器、卷和网络 |
90+
| `docker system prune -a -f` | 强制清理所有未使用的镜像、容器、卷和网络 |
91+
| `docker container prune` | 清理未使用的容器 |
92+
| `docker image prune` | 清理未使用的镜像 |
93+
| `docker volume prune` | 清理未使用的卷 |
94+
| `docker network prune` | 清理未使用的网络 |
95+
| `docker system df` | 查看Docker资源使用情况 |
96+
97+
98+
## Docker Compose
99+
100+
| 命令 | 说明 |
101+
|-----------------------|-----------|
102+
| `docker-compose up` | 启动并运行所有服务 |
103+
| `docker-compose down` | 停止并删除所有服务 |
104+
| `docker-compose ps` | 查看所有服务状态 |
105+
| `docker-compose logs` | 查看所有服务日志 |
106+
107+
108+

0 commit comments

Comments
 (0)