forked from wyp0596/docker-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
701 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
# docker 教程(从零开始学docker) | ||
|
||
|
||
# docker 教程 | ||
|
||
## 初级教程 | ||
|
||
[docker是什么](/primary/docker_info.md) | ||
|
||
[安装docker](/primary/docker_install.md) | ||
[安装docker](/primary/docker_install.md) | ||
|
||
[Registry——镜像仓库](/primary/docker_registry.md) | ||
|
||
[Image——镜像](/primary/docker_image.md) | ||
|
||
[Container——容器](/primary/docker_container.md) | ||
|
||
|
||
|
||
### 中级教程 | ||
|
||
[Docker的清理](/intermediate/docker_cleanup.md) | ||
|
||
[Docker搭建开发环境](/intermediate/docker_dev.md) | ||
|
||
[Docker服务编排——compose](/intermediate/docker_compose.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Docker的清理 | ||
|
||
> Docker 会占用一定的磁盘空间,若不需要可以进行清理 | ||
## 容器 | ||
|
||
```shell | ||
# 强制删除并清理容器,包括数据卷 | ||
docker rm -vf container-name | ||
|
||
# 清理退出的容器 | ||
docker rm $(docker ps -q -f status=exited) | ||
|
||
# 杀死所有正在运行的容器 | ||
docker kill $(docker ps -a -q) | ||
|
||
# 删除所有已经停止的容器 | ||
docker rm $(docker ps -a -q) | ||
``` | ||
|
||
|
||
|
||
|
||
|
||
## 镜像 | ||
|
||
```shell | ||
|
||
|
||
# 清理虚悬镜像 | ||
docker rmi $(docker images -q -f "dangling=true") | ||
|
||
# 删除所有虚悬镜像 | ||
docker rmi $(docker images -q -f dangling=true) | ||
|
||
# 删除所有镜像 | ||
docker rmi $(docker images -q) | ||
``` | ||
|
||
|
||
|
||
## 数据卷 | ||
|
||
|
||
|
||
```shell | ||
# 列出虚悬数据卷 | ||
docker volume ls -qf dangling=true | ||
# 删除虚悬数据卷 | ||
docker volume rm $(docker volume ls -qf dangling=true) | ||
``` | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Docker服务编排——compose | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Docker搭建开发环境 | ||
|
||
> 利用 Docker 可以非常方便快速地搭建开发环境 | ||
|
||
|
||
### MySQL | ||
|
||
> [官方Repository](https://hub.docker.com/_/mysql/) | ||
### 运行 | ||
|
||
`docker run --name some-mysql -p 3306:3306 -v ~/my_data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=admin -d mysql --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci` | ||
|
||
说明: | ||
|
||
1. `some-mysql` 是自定义的容器名称 | ||
2. `-p 3306:3306` 是端口映射配置 | ||
3. `~/my_data/mysql` 代表存储mysql的配置以及数据的目录 | ||
|
||
### 连接测试 | ||
|
||
`docker run -it --link some-mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'` | ||
|
||
## Redis | ||
|
||
> [官方Repository](https://hub.docker.com/_/redis/) | ||
### 运行 | ||
|
||
`docker run --name some-redis -d -p 6379:6379 redis:alpine redis-server` | ||
|
||
说明: | ||
|
||
1. `some-redis` 是自定义的容器名称 | ||
2. `-p 6379:6379` 是端口映射配置 | ||
|
||
### 连接测试 | ||
|
||
`docker run -it --link some-redis:redis --rm redis:alpine redis-cli -h redis -p 6379` | ||
|
||
|
||
|
||
## Mongo | ||
|
||
> [官方Repository](https://hub.docker.com/_/mongo/) | ||
### 运行 | ||
|
||
`docker run --name some-mongo -v ~/my_data/mongo:/data/db -d -p 27017:27017 mongo` | ||
|
||
说明: | ||
|
||
1. `some-mongo` 是自定义的容器名称 | ||
2. `-p 27017:27017` 是端口映射配置 | ||
3. `~/my_data/mongo` 代表存储mongo的配置以及数据的目录 | ||
|
||
### 连接测试 | ||
|
||
`docker run -it --link some-mongo:mongo --rm mongo sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/test"'` | ||
|
||
|
||
|
||
## Nginx | ||
|
||
> [官方Repository](https://hub.docker.com/_/nginx/) | ||
### 运行 | ||
|
||
`docker run --name some-nginx -v ~/my_data/nginx:/usr/share/nginx/html:ro -d -p 8080:80 nginx:alpine` | ||
|
||
说明: | ||
|
||
1. `some-nginx` 是自定义的容器名称 | ||
2. `-p 8080:80` 是端口映射配置 | ||
3. `~/my_data/nginx` 代表存储nginx静态文件的目录 | ||
|
||
## openjdk | ||
|
||
> [官方Repository](https://hub.docker.com/_/openjdk/) | ||
|
||
|
||
## Node | ||
|
||
> [官方Repository](https://hub.docker.com/_/node/) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Container——容器 | ||
|
||
> Docker 容器是镜像的运行时,容器运行并不会影响镜像的内容,一个镜像可以运行多个容器。 | ||
|
||
|
||
## 启动 | ||
|
||
### 新建并启动 | ||
|
||
```shell | ||
# -t 分配伪终端并绑定到容器标准输出 -i 让容器标准输入打开 | ||
# docker run 创建容器 | ||
sudo docker run -t -i ubuntu:14.04 /bin/bash | ||
pwd | ||
ls | ||
``` | ||
|
||
1. 若本地不存在镜像会自动下载 | ||
2. 利用镜像创建并启动容器 | ||
3. 分配一个文件系统,并在只读镜像层外挂载一层读写层 | ||
4. 从宿主主机配置的网桥接口中桥接一个虚拟接口到容器中去 | ||
5. 从地址池配置一个 ip 地址给容器 | ||
6. 执行用户指定的应用程序 | ||
7. 执行完毕后容器被终止 | ||
|
||
### 启动已终止的容器 | ||
|
||
`docker start <容器标识>` | ||
|
||
|
||
|
||
## 守护态运行 | ||
|
||
通常通过参数`-d`实现 | ||
|
||
要获取容器的输出信息,可以通过 `docker logs` 命令 | ||
|
||
|
||
|
||
## 终止 | ||
|
||
1. `docker stop <容器标识>`来终止守护态运行中的容器 | ||
|
||
2. `exit`或`Ctrl+d`来退出终端容器 | ||
|
||
3. 终止状态的容器可以用 `docker ps -a` 命令看到 | ||
|
||
4. 处于终止状态的容器,可以通过 `docker start <容器标识>` 命令来重新启动 | ||
|
||
5. `docker restart <容器标识>` 命令会将一个运行态的容器终止,然后再重新启动它 | ||
|
||
| ||
|
||
## 进入容器 | ||
|
||
进入守护态运行中的容器 | ||
|
||
### `attach`命令 | ||
|
||
`docker attach <容器标识>` | ||
|
||
当多个窗口同时 `attach` 到同一个容器的时候,所有窗口都会同步显示 | ||
|
||
### `nsenter`命令 | ||
|
||
[方法步骤](https://yeasy.gitbooks.io/docker_practice/content/container/enter.html) | ||
|
||
## 导出和导入 | ||
|
||
### 导出容器 | ||
|
||
`docker export 7691a814370e > ubuntu.tar` | ||
|
||
### 导入容器 | ||
|
||
`cat ubuntu.tar | sudo docker import - test/ubuntu:v1.0` | ||
|
||
## 删除 | ||
|
||
1. 删除终止状态容器`docker rm <容器标识>` | ||
2. 强制删除运行中的容器`docker rm -f <容器标识>` | ||
3. 清理所有处于终止状态的容器`docker rm $(docker ps -a -q)` | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
## 参考 | ||
|
||
[Docker — 从入门到实践](https://yeasy.gitbooks.io/docker_practice/content/) | ||
|
||
|
||
|
Oops, something went wrong.