51 Commits

Author SHA1 Message Date
Kang Huaishuai
dc0f1223a0 Merge pull request #477 from caisah/patch-2
Fix typo in english/basic_concept/container.md
2020-11-15 20:45:31 +08:00
caisah
dad6b9f022 Fix typo in english/basic_concept/container.md 2020-11-15 14:42:21 +02:00
Kang Huaishuai
e049bf2741 Merge pull request #475 from caisah/patch-1
Fix typo
2020-11-15 20:09:37 +08:00
caisah
e59b50b43b Fix typo 2020-11-15 14:05:46 +02:00
Kang Huaishuai
8888612782 Merge pull request #474 from Bill0412/english
translate image/list.md to English
2020-11-09 13:12:47 +08:00
Dorsey.Xu
aa431b9a79 update image/list.md 2020-11-04 18:03:35 +08:00
Kang Huaishuai
500325b7c8 Merge pull request #472 from Bill0412/english
Translate image/pull.md to English
2020-10-28 21:25:56 +08:00
Dorsey.Xu
cba52767b7 translate image/pull.md 2020-10-28 13:18:34 +08:00
Dorsey.Xu
dc3a1c92d5 translage image/README.md 2020-10-28 10:13:00 +08:00
Kang Huaishuai
2ae8979c5c Merge pull request #470 from Bill0412/english
Translate the install chapter to English
2020-10-26 17:09:50 +08:00
Dorsey.Xu
41633ecf24 update install/mirror.md 2020-10-26 16:35:34 +08:00
Dorsey.Xu
48bcb9470b update install/windows.md 2020-10-26 15:30:35 +08:00
Dorsey.Xu
d47f565e83 translate install/mac.md 2020-10-26 15:26:51 +08:00
Dorsey.Xu
b54b5b0a0f translate install/raspberry-pi.md 2020-10-26 15:03:45 +08:00
Dorsey.Xu
6c8e710c53 translate install/centos.md 2020-10-26 14:47:10 +08:00
Dorsey.Xu
27f495466d translate install/fedora.md 2020-10-26 14:08:12 +08:00
Dorsey.Xu
cc8c36b1a3 translate install/debian.md 2020-10-26 13:54:27 +08:00
Dorsey.Xu
f4e21a70b1 update install/ubuntu.md 2020-10-26 13:33:37 +08:00
Dorsey.Xu
a2cdfdfded translate install/README.md 2020-10-26 13:21:10 +08:00
Kang Huaishuai
3b0f3c0cb2 Merge pull request #469 from Bill0412/english
Translate Basic Concept
2020-10-23 23:17:41 +08:00
Dorsey.Xu
37581d3016 translate basic_concept/repository.md 2020-10-23 18:06:39 +08:00
Dorsey.Xu
49fd7a94da fix: typo in container.md 2020-10-23 15:52:50 +08:00
Dorsey.Xu
0a8887957e rewrite basic_concept/README.md 2020-10-23 15:50:50 +08:00
Dorsey.Xu
3356aa627f rewrite basic_concept/container.md 2020-10-23 15:46:45 +08:00
Dorsey.Xu
f20936e0af fix: typo in us-en link 2020-10-23 14:49:43 +08:00
Kang Huaishuai
247bbcdc59 Merge pull request #468 from Bill0412/english
update image.md
2020-10-23 10:34:39 +08:00
Dorsey.Xu
efdc3de9e0 update image.md 2020-10-23 10:20:46 +08:00
Kang Huaishuai
42bb1bd1a1 Update README.md 2020-10-22 14:20:32 +08:00
Kang Huaishuai
c5935658bb remove machine meos 2020-10-22 14:17:54 +08:00
Kang Huaishuai
bc6d6c85e3 Merge pull request #467 from Bill0412/english
update introduction part of the English version
2020-10-22 14:16:27 +08:00
Dorsey.Xu
ff7d5976a7 update introduction 2020-10-22 14:09:10 +08:00
Kang Huaishuai
3a3939686c Merge pull request #422 from 00Kai0/english
update image
2019-10-02 22:06:52 +08:00
Kerwin.Sun
1a966e2979 update image 2019-10-02 22:03:48 +08:00
Kang Huaishuai
a7d3a8291f Merge pull request #421 from 00Kai0/english
update ubuntu.md
2019-09-06 16:39:39 +08:00
Kang Huaishuai
6f9a5cca90 Update ubuntu.md 2019-09-06 16:39:12 +08:00
Kerwin.Sun
a5b762c2ce update 2019-09-06 16:27:21 +08:00
Kang HuaiShuai
3cdde73798 add docker-practice.com
Signed-off-by: Kang HuaiShuai <khs1994@khs1994.com>
2019-09-05 13:39:32 +08:00
Kang HuaiShuai
e9213ea244 deploy pages to docker-practice/us-en 2019-09-05 13:06:29 +08:00
Kang Huaishuai
2b6e28d6a9 Fixed error 2019-09-01 20:02:48 +08:00
Kang Huaishuai
0699e96e36 Merge branch 'master' into english 2019-09-01 19:58:45 +08:00
Kang Huaishuai
2069a436e1 Merge pull request #419 from 00Kai0/english
update windows.md
2019-09-01 19:30:47 +08:00
Kang Huaishuai
7b808e4d3d Update windows.md 2019-09-01 19:30:11 +08:00
Kerwin.Sun
a071218f77 update 2019-09-01 18:27:36 +08:00
Kang Huaishuai
c9ebe3da2b Merge pull request #417 from 00Kai0/english
Update `why.md`
2019-08-30 14:58:14 +08:00
Kerwin.Sun
941e01623c why.md 2019-08-30 14:50:51 +08:00
Kerwin.Sun
d00b6e1911 trans introduction--why 2019-08-11 18:49:23 +08:00
khs1994
3b959abf68 Update SUMMARY 2019-05-14 00:17:11 +08:00
khs1994
8280d40922 Update gitbook settings 2019-05-13 23:41:43 +08:00
khs1994
1c1d81bd49 Update travis ci settings 2019-05-13 23:06:39 +08:00
khs1994
4f48fc2066 Merge pull request #402 from 00Kai0/english
trans introduction's README.md and what.md
2019-05-13 23:02:09 +08:00
00kai0
3974a2de24 trans introduction's README.md and what.md 2019-05-13 15:34:13 +08:00
24 changed files with 502 additions and 865 deletions

View File

@@ -23,17 +23,17 @@ after_success:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker build -t dockerpracticesig/docker_practice . - docker build -t dockerpracticesig/docker_practice:us-en .
- docker run -dit --rm -p 4000:80 dockerpracticesig/docker_practice - docker run -dit --rm -p 4000:80 dockerpracticesig/docker_practice:us-en
- sleep 5 - sleep 5
- curl 127.0.0.1:4000 - curl 127.0.0.1:4000
- docker push dockerpracticesig/docker_practice - docker push dockerpracticesig/docker_practice:us-en
- cd _book - cd _book
- git init - git init
- git remote add origin "$REPO" - git remote add origin "$DEPLOY_REPO"
- git add . - git add .
- COMMIT=`date "+%F %T"` - COMMIT=`date "+%F %T"`
- git commit -m "Travis CI Site updated $COMMIT" - git commit -m "Travis CI Site updated $COMMIT"
@@ -41,9 +41,8 @@ after_success:
env: env:
global: global:
- DEPLOY_BRANCH: pages - DEPLOY_BRANCH: master
# - DEPLOY_BRANCH: legacy-pages - DEPLOY_REPO: git@github.com:docker-practice/us-en.git
- REPO: git@github.com:yeasy/docker_practice.git
addons: addons:
ssh_known_hosts: ssh_known_hosts:
@@ -51,6 +50,4 @@ addons:
branches: branches:
only: only:
- master - english
- dev
# - docker-legacy

View File

@@ -1,4 +1,4 @@
# Docker 从入门到实践 # Docker 从入门到实践英文版
[![](https://img.shields.io/github/stars/yeasy/docker_practice.svg?style=social&label=Stars)](https://github.com/yeasy/docker_practice) [![](https://travis-ci.org/yeasy/docker_practice.svg?branch=master)](https://travis-ci.org/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%20v18.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)](https://union-click.jd.com/jdc?e=&p=AyIGZRtYFAcXBFIZWR0yEgRQH1kXAhs3EUQDS10iXhBeGlcJDBkNXg9JHU4YDk5ER1xOGRNLGEEcVV8BXURFUFdfC0RVU1JRUy1OVxUBFwNXGVscMlVYLlAaXAV1Z1JHA0dWEHVXZTliY1QLWStaJQAWB10fXhwKEDdlG1wlUHzf462DsLMO0%2F%2BUjp2VIgZlG18RBBcCUBlbEAoTBWUcWxwySVI7HAhBBxEOBUgOFQYQUGUraxYyIjdVK1glQHxXUEhYEVEUUFQcC0IHGgRRSAgVARAPAhsLFgNCDl0ZWiUAEwZREg%3D%3D&t=W1dCFFlQCxxKQgFHREkdSVJKSQVJHFRXFk9FUlpGQUpLCVBaTFhbXQtWVmpSWRtYEAYQBVUS) [![](https://img.shields.io/github/stars/yeasy/docker_practice.svg?style=social&label=Stars)](https://github.com/yeasy/docker_practice) [![](https://travis-ci.org/yeasy/docker_practice.svg?branch=master)](https://travis-ci.org/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%20v18.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)](https://union-click.jd.com/jdc?e=&p=AyIGZRtYFAcXBFIZWR0yEgRQH1kXAhs3EUQDS10iXhBeGlcJDBkNXg9JHU4YDk5ER1xOGRNLGEEcVV8BXURFUFdfC0RVU1JRUy1OVxUBFwNXGVscMlVYLlAaXAV1Z1JHA0dWEHVXZTliY1QLWStaJQAWB10fXhwKEDdlG1wlUHzf462DsLMO0%2F%2BUjp2VIgZlG18RBBcCUBlbEAoTBWUcWxwySVI7HAhBBxEOBUgOFQYQUGUraxYyIjdVK1glQHxXUEhYEVEUUFQcC0IHGgRRSAgVARAPAhsLFgNCDl0ZWiUAEwZREg%3D%3D&t=W1dCFFlQCxxKQgFHREkdSVJKSQVJHFRXFk9FUlpGQUpLCVBaTFhbXQtWVmpSWRtYEAYQBVUS)
@@ -6,8 +6,8 @@
| 语言 | 构建状态 | - | | 语言 | 构建状态 | - |
| :------------- | :------------- | :--- | | :------------- | :------------- | :--- |
| [zh-hans](https://github.com/yeasy/docker_practice) | [![](https://travis-ci.org/yeasy/docker_practice.svg?branch=master)](https://travis-ci.org/yeasy/docker_practice)| [阅读](https://docker_practice.gitee.io/) | | [zh-hans](https://github.com/yeasy/docker_practice) | [![](https://travis-ci.org/yeasy/docker_practice.svg?branch=master)](https://travis-ci.org/yeasy/docker_practice)| [阅读](https://docker_practice.gitee.io/zh-cn) |
| [us-en](https://github.com/yeasy/docker_practice/tree/english) | [![](https://travis-ci.org/yeasy/docker_practice.svg?branch=english)](https://travis-ci.org/yeasy/docker_practice)| [阅读](https://docker_practice.gitee.io/us_en) | | [us-en](https://github.com/yeasy/docker_practice/tree/english) | [![](https://travis-ci.org/yeasy/docker_practice.svg?branch=english)](https://travis-ci.org/yeasy/docker_practice)| [阅读](https://docker_practice.gitee.io/us-en) |
| [zh-hant](https://github.com/yeasy/docker_practice/tree/zh-Hant) | [![](https://travis-ci.org/yeasy/docker_practice.svg?branch=zh-hant)](https://travis-ci.org/yeasy/docker_practice)| [阅读](https://docker_practice.gitee.io/zh_hant) | | [zh-hant](https://github.com/yeasy/docker_practice/tree/zh-Hant) | [![](https://travis-ci.org/yeasy/docker_practice.svg?branch=zh-hant)](https://travis-ci.org/yeasy/docker_practice)| [阅读](https://docker_practice.gitee.io/zh_hant) |
[Docker](https://www.docker.com) 是个划时代的开源项目,它彻底释放了计算虚拟化的威力,极大提高了应用的维护效率,降低了云计算应用开发的成本!使用 Docker可以让应用的部署、测试和分发都变得前所未有的高效和轻松 [Docker](https://www.docker.com) 是个划时代的开源项目,它彻底释放了计算虚拟化的威力,极大提高了应用的维护效率,降低了云计算应用开发的成本!使用 Docker可以让应用的部署、测试和分发都变得前所未有的高效和轻松
@@ -16,7 +16,7 @@
本书既适用于具备基础 Linux 知识的 Docker 初学者也希望可供理解原理和实现的高级用户参考同时书中给出的实践案例可供在进行实际部署时借鉴前六章为基础内容供用户理解 Docker 的基本概念和操作7 ~ 9 章介绍包括数据管理网络等高级操作 10 ~ 13 章介绍了容器生态中的几个核心项目1415 章讨论了关于 Docker 安全和实现技术等高级话题后续章节则分别介绍包括 EtcdCoreOSKubernetesMesos容器云等相关热门开源项目最后还展示了使用容器技术的典型的应用场景和实践案例 本书既适用于具备基础 Linux 知识的 Docker 初学者也希望可供理解原理和实现的高级用户参考同时书中给出的实践案例可供在进行实际部署时借鉴前六章为基础内容供用户理解 Docker 的基本概念和操作7 ~ 9 章介绍包括数据管理网络等高级操作 10 ~ 13 章介绍了容器生态中的几个核心项目1415 章讨论了关于 Docker 安全和实现技术等高级话题后续章节则分别介绍包括 EtcdCoreOSKubernetesMesos容器云等相关热门开源项目最后还展示了使用容器技术的典型的应用场景和实践案例
* 在线阅读[GitBook](https://yeasy.gitbooks.io/docker_practice/content/)[Github](https://github.com/yeasy/docker_practice/blob/master/SUMMARY.md)[GitBook 国内镜像](https://docker_practice.gitee.io/)[GitBook 英文版国内镜像](https://docker_practice.gitee.io/us_en)[国内镜像](https://github.com/yeasy/docker_practice/wiki/%E9%A1%B9%E7%9B%AE%E5%9B%BD%E5%86%85%E9%95%9C%E5%83%8F) * 在线阅读[docker-practice.com](https://docker-practice.com/)[GitBook](https://yeasy.gitbooks.io/docker_practice/content/)[Github](https://github.com/yeasy/docker_practice/blob/master/SUMMARY.md)[GitBook 国内镜像](https://docker_practice.gitee.io/zh-cn)[GitBook 英文版国内镜像](https://docker_practice.gitee.io/us_en)[国内镜像](https://github.com/yeasy/docker_practice/wiki/%E9%A1%B9%E7%9B%AE%E5%9B%BD%E5%86%85%E9%95%9C%E5%83%8F)
* 下载[pdf](https://github.com/yeasy/docker_practice/wiki/%E4%B8%8B%E8%BD%BD)[epub](https://github.com/yeasy/docker_practice/wiki/%E4%B8%8B%E8%BD%BD) * 下载[pdf](https://github.com/yeasy/docker_practice/wiki/%E4%B8%8B%E8%BD%BD)[epub](https://github.com/yeasy/docker_practice/wiki/%E4%B8%8B%E8%BD%BD)
* [离线阅读 `$ docker run -it --rm -p 4000:80 dockerpracticesig/docker_practice`](https://github.com/yeasy/docker_practice/wiki/%E7%A6%BB%E7%BA%BF%E9%98%85%E8%AF%BB%E5%8A%9F%E8%83%BD%E8%AF%A6%E8%A7%A3) * [离线阅读 `$ docker run -it --rm -p 4000:80 dockerpracticesig/docker_practice`](https://github.com/yeasy/docker_practice/wiki/%E7%A6%BB%E7%BA%BF%E9%98%85%E8%AF%BB%E5%8A%9F%E8%83%BD%E8%AF%A6%E8%A7%A3)
* [英文翻译](https://github.com/yeasy/docker_practice/issues/363) * [英文翻译](https://github.com/yeasy/docker_practice/issues/363)
@@ -57,12 +57,6 @@ Docker 自身仍在快速发展中,生态环境也在蓬勃成长。建议初
[Docker 技术入门与实战](https://union-click.jd.com/jdc?e=&p=AyIGZRtYFAcXBFIZWR0yEgRQH1kXAhs3EUQDS10iXhBeGlcJDBkNXg9JHU4YDk5ER1xOGRNLGEEcVV8BXURFUFdfC0RVU1JRUy1OVxUBFwNXGVscMlVYLlAaXAV1Z1JHA0dWEHVXZTliY1QLWStaJQAWB10fXhwKEDdlG1wlUHzf462DsLMO0%2F%2BUjp2VIgZlG18RBBcCUBlbEAoTBWUcWxwySVI7HAhBBxEOBUgOFQYQUGUraxYyIjdVK1glQHxXUEhYEVEUUFQcC0IHGgRRSAgVARAPAhsLFgNCDl0ZWiUAEwZREg%3D%3D&t=W1dCFFlQCxxKQgFHREkdSVJKSQVJHFRXFk9FUlpGQUpLCVBaTFhbXQtWVmpSWRtYEAYQBVUS)》第三版已经面世,介绍最新的容器技术栈,欢迎大家阅读使用并反馈建议。 [Docker 技术入门与实战](https://union-click.jd.com/jdc?e=&p=AyIGZRtYFAcXBFIZWR0yEgRQH1kXAhs3EUQDS10iXhBeGlcJDBkNXg9JHU4YDk5ER1xOGRNLGEEcVV8BXURFUFdfC0RVU1JRUy1OVxUBFwNXGVscMlVYLlAaXAV1Z1JHA0dWEHVXZTliY1QLWStaJQAWB10fXhwKEDdlG1wlUHzf462DsLMO0%2F%2BUjp2VIgZlG18RBBcCUBlbEAoTBWUcWxwySVI7HAhBBxEOBUgOFQYQUGUraxYyIjdVK1glQHxXUEhYEVEUUFQcC0IHGgRRSAgVARAPAhsLFgNCDl0ZWiUAEwZREg%3D%3D&t=W1dCFFlQCxxKQgFHREkdSVJKSQVJHFRXFk9FUlpGQUpLCVBaTFhbXQtWVmpSWRtYEAYQBVUS)》第三版已经面世,介绍最新的容器技术栈,欢迎大家阅读使用并反馈建议。
<p align="center">
<img width="200" src="https://user-images.githubusercontent.com/16733187/57310918-3c3afd80-711d-11e9-8816-266e5ede70bb.jpg">
</p>
<p align="center"><strong>微信扫码购买~</strong></p>
* [京东图书](https://union-click.jd.com/jdc?e=&p=AyIGZRtYFAcXBFIZWR0yEgRQH1kXAhs3EUQDS10iXhBeGlcJDBkNXg9JHU4YDk5ER1xOGRNLGEEcVV8BXURFUFdfC0RVU1JRUy1OVxUBFwNXGVscMlVYLlAaXAV1Z1JHA0dWEHVXZTliY1QLWStaJQAWB10fXhwKEDdlG1wlUHzf462DsLMO0%2F%2BUjp2VIgZlG18RBBcCUBlbEAoTBWUcWxwySVI7HAhBBxEOBUgOFQYQUGUraxYyIjdVK1glQHxXUEhYEVEUUFQcC0IHGgRRSAgVARAPAhsLFgNCDl0ZWiUAEwZREg%3D%3D&t=W1dCFFlQCxxKQgFHREkdSVJKSQVJHFRXFk9FUlpGQUpLCVBaTFhbXQtWVmpSWRtYEAYQBVUS) * [京东图书](https://union-click.jd.com/jdc?e=&p=AyIGZRtYFAcXBFIZWR0yEgRQH1kXAhs3EUQDS10iXhBeGlcJDBkNXg9JHU4YDk5ER1xOGRNLGEEcVV8BXURFUFdfC0RVU1JRUy1OVxUBFwNXGVscMlVYLlAaXAV1Z1JHA0dWEHVXZTliY1QLWStaJQAWB10fXhwKEDdlG1wlUHzf462DsLMO0%2F%2BUjp2VIgZlG18RBBcCUBlbEAoTBWUcWxwySVI7HAhBBxEOBUgOFQYQUGUraxYyIjdVK1glQHxXUEhYEVEUUFQcC0IHGgRRSAgVARAPAhsLFgNCDl0ZWiUAEwZREg%3D%3D&t=W1dCFFlQCxxKQgFHREkdSVJKSQVJHFRXFk9FUlpGQUpLCVBaTFhbXQtWVmpSWRtYEAYQBVUS)
* [China-Pub](http://product.china-pub.com/8052127) * [China-Pub](http://product.china-pub.com/8052127)

View File

@@ -1,16 +1,16 @@
# [Docker 从入门到实践](https://github.com/yeasy/docker_practice/blob/master/SUMMARY.md) # [Docker 从入门到实践英文版](https://github.com/yeasy/docker_practice/blob/english/SUMMARY.md)
* [前言](README.md) * [README](README.md)
* [修订记录](CHANGELOG.md) * [CHANGELOG](CHANGELOG.md)
* [如何贡献](CONTRIBUTING.md) * [CONTRIBUTING](CONTRIBUTING.md)
* [Docker 简介](introduction/README.md) * [Introduction](introduction/README.md)
* [什么是 Docker](introduction/what.md) * [What is Docker](introduction/what.md)
* [为什么要用 Docker](introduction/why.md) * [Why Docker](introduction/why.md)
* [基本概念](basic_concept/README.md) * [Basic concept](basic_concept/README.md)
* [镜像](basic_concept/image.md) * [Image](basic_concept/image.md)
* [容器](basic_concept/container.md) * [Container](basic_concept/container.md)
* [仓库](basic_concept/repository.md) * [Repository](basic_concept/repository.md)
* [安装 Docker](install/README.md) * [Get Docker](install/README.md)
* [Ubuntu](install/ubuntu.md) * [Ubuntu](install/ubuntu.md)
* [Debian](install/debian.md) * [Debian](install/debian.md)
* [Fedora](install/fedora.md) * [Fedora](install/fedora.md)
@@ -18,140 +18,129 @@
* [Raspberry Pi](install/raspberry-pi.md) * [Raspberry Pi](install/raspberry-pi.md)
* [macOS](install/mac.md) * [macOS](install/mac.md)
* [Windows PC](install/windows.md) * [Windows PC](install/windows.md)
* [镜像加速器](install/mirror.md) * [Mirror](install/mirror.md)
* [使用镜像](image/README.md) * [Image](image/README.md)
* [获取镜像](image/pull.md) * [pull](image/pull.md)
* [列出镜像](image/list.md) * [list](image/list.md)
* [删除本地镜像](image/rm.md) * [Delete](image/rm.md)
* [利用 commit 理解镜像构成](image/commit.md) * [commit](image/commit.md)
* [使用 Dockerfile 定制镜像](image/build.md) * [Dockerfile](image/build.md)
* [Dockerfile 指令详解](image/dockerfile/README.md) * [Dockerfile reference](image/dockerfile/README.md)
* [COPY 复制文件](image/dockerfile/copy.md) * [COPY](image/dockerfile/copy.md)
* [ADD 更高级的复制文件](image/dockerfile/add.md) * [ADD](image/dockerfile/add.md)
* [CMD 容器启动命令](image/dockerfile/cmd.md) * [CMD](image/dockerfile/cmd.md)
* [ENTRYPOINT 入口点](image/dockerfile/entrypoint.md) * [ENTRYPOINT](image/dockerfile/entrypoint.md)
* [ENV 设置环境变量](image/dockerfile/env.md) * [ENV](image/dockerfile/env.md)
* [ARG 构建参数](image/dockerfile/arg.md) * [ARG](image/dockerfile/arg.md)
* [VOLUME 定义匿名卷](image/dockerfile/volume.md) * [VOLUME](image/dockerfile/volume.md)
* [EXPOSE 暴露端口](image/dockerfile/expose.md) * [EXPOSE](image/dockerfile/expose.md)
* [WORKDIR 指定工作目录](image/dockerfile/workdir.md) * [WORKDIR](image/dockerfile/workdir.md)
* [USER 指定当前用户](image/dockerfile/user.md) * [USER](image/dockerfile/user.md)
* [HEALTHCHECK 健康检查](image/dockerfile/healthcheck.md) * [HEALTHCHECK](image/dockerfile/healthcheck.md)
* [ONBUILD 为他人作嫁衣裳](image/dockerfile/onbuild.md) * [ONBUILD](image/dockerfile/onbuild.md)
* [参考文档](image/dockerfile/references.md) * [References](image/dockerfile/references.md)
* [Dockerfile 多阶段构建](image/multistage-builds/README.md) * [Multistage builds](image/multistage-builds/README.md)
* [实战多阶段构建 Laravel 镜像](image/multistage-builds/laravel.md) * [Multistage builds Laravel](image/multistage-builds/laravel.md)
* [构建多种系统架构支持的 Docker 镜像](image/manifest.md) * [manifest](image/manifest.md)
* [使用 BuildKit 构建镜像](image/buildkit.md) * [BuildKit](image/buildkit.md)
* [其它制作镜像的方式](image/other.md) * [Other](image/other.md)
* [实现原理](image/internal.md) * [Internal](image/internal.md)
* [操作容器](container/README.md) * [Container](container/README.md)
* [启动](container/run.md) * [run](container/run.md)
* [守护态运行](container/daemon.md) * [Daemon](container/daemon.md)
* [终止](container/stop.md) * [stop](container/stop.md)
* [进入容器](container/attach_exec.md) * [exec](container/attach_exec.md)
* [导出和导入](container/import_export.md) * [Import and export](container/import_export.md)
* [删除](container/rm.md) * [Delete](container/rm.md)
* [访问仓库](repository/README.md) * [Repository](repository/README.md)
* [Docker Hub](repository/dockerhub.md) * [Docker Hub](repository/dockerhub.md)
* [私有仓库](repository/registry.md) * [Docker Registry](repository/registry.md)
* [私有仓库高级配置](repository/registry_auth.md) * [Docker Registry TLS](repository/registry_auth.md)
* [Nexus 3](repository/nexus3_registry.md) * [Nexus 3](repository/nexus3_registry.md)
* [数据管理](data_management/README.md) * [Data management](data_management/README.md)
* [数据卷](data_management/volume.md) * [Volumes](data_management/volume.md)
* [挂载主机目录](data_management/bind-mounts.md) * [Bind mounts](data_management/bind-mounts.md)
* [使用网络](network/README.md) * [Network](network/README.md)
* [外部访问容器](network/port_mapping.md) * [Port mapping](network/port_mapping.md)
* [容器互联](network/linking.md) * [Linking](network/linking.md)
* [配置 DNS](network/dns.md) * [DNS](network/dns.md)
* [高级网络配置](advanced_network/README.md) * [Advanced network](advanced_network/README.md)
* [快速配置指南](advanced_network/quick_guide.md) * [Guide](advanced_network/quick_guide.md)
* [容器访问控制](advanced_network/access_control.md) * [Access control](advanced_network/access_control.md)
* [端口映射实现](advanced_network/port_mapping.md) * [Port mapping](advanced_network/port_mapping.md)
* [配置 docker0 网桥](advanced_network/docker0.md) * [docker0](advanced_network/docker0.md)
* [自定义网桥](advanced_network/bridge.md) * [Bridge](advanced_network/bridge.md)
* [工具和示例](advanced_network/example.md) * [Example](advanced_network/example.md)
* [编辑网络配置文件](advanced_network/config_file.md) * [Config](advanced_network/config_file.md)
* [实例创建一个点到点连接](advanced_network/ptp.md) * [PTP](advanced_network/ptp.md)
* [Docker 三剑客之 Compose 项目](compose/README.md) * [Docker Compose](compose/README.md)
* [简介](compose/introduction.md) * [Introduction](compose/introduction.md)
* [安装与卸载](compose/install.md) * [Install](compose/install.md)
* [使用](compose/usage.md) * [Usage](compose/usage.md)
* [命令说明](compose/commands.md) * [Commands](compose/commands.md)
* [Compose 模板文件](compose/compose_file.md) * [Compose file reference](compose/compose_file.md)
* [实战 Django](compose/django.md) * [Django](compose/django.md)
* [实战 Rails](compose/rails.md) * [Rails](compose/rails.md)
* [实战 WordPress](compose/wordpress.md) * [WordPress](compose/wordpress.md)
* [Docker 三剑客之 Machine 项目](machine/README.md) * [Docker Swarm](swarm/README.md)
* [安装](machine/install.md)
* [使用](machine/usage.md)
* [Docker 三剑客之 Docker Swarm](swarm/README.md)
* [Swarm mode](swarm_mode/README.md) * [Swarm mode](swarm_mode/README.md)
* [基本概念](swarm_mode/overview.md) * [Overview](swarm_mode/overview.md)
* [创建 Swarm 集群](swarm_mode/create.md) * [Create](swarm_mode/create.md)
* [部署服务](swarm_mode/deploy.md) * [Deploy](swarm_mode/deploy.md)
* [使用 compose 文件](swarm_mode/stack.md) * [Stack](swarm_mode/stack.md)
* [管理密钥](swarm_mode/secret.md) * [Secret](swarm_mode/secret.md)
* [管理配置信息](swarm_mode/config.md) * [Config](swarm_mode/config.md)
* [滚动升级](swarm_mode/rolling_update.md) * [Rolling update](swarm_mode/rolling_update.md)
* [安全](security/README.md) * [Security](security/README.md)
* [内核命名空间](security/kernel_ns.md) * [namespace](security/kernel_ns.md)
* [控制组](security/control_group.md) * [cgroups](security/control_group.md)
* [服务端防护](security/daemon_sec.md) * [Daemon sec](security/daemon_sec.md)
* [内核能力机制](security/kernel_capability.md) * [Kernel capability](security/kernel_capability.md)
* [其它安全特性](security/other_feature.md) * [Other feature](security/other_feature.md)
* [总结](security/summary.md) * [SUMMARY](security/summary.md)
* [底层实现](underly/README.md) * [Underly](underly/README.md)
* [基本架构](underly/arch.md) * [Arch](underly/arch.md)
* [命名空间](underly/namespace.md) * [namespace](underly/namespace.md)
* [控制组](underly/cgroups.md) * [cgroups](underly/cgroups.md)
* [联合文件系统](underly/ufs.md) * [ufs](underly/ufs.md)
* [容器格式](underly/container_format.md) * [Container format](underly/container_format.md)
* [网络](underly/network.md) * [Network](underly/network.md)
* [Etcd 项目](etcd/README.md) * [Etcd](etcd/README.md)
* [简介](etcd/intro.md) * [Introduction](etcd/intro.md)
* [安装](etcd/install.md) * [Install](etcd/install.md)
* [集群](etcd/cluster.md) * [Cluster](etcd/cluster.md)
* [使用 etcdctl](etcd/etcdctl.md) * [etcdctl](etcd/etcdctl.md)
* [CoreOS 项目](coreos/README.md) * [CoreOS](coreos/README.md)
* [简介](coreos/intro.md) * [Introduction](coreos/intro.md)
* [工具](coreos/intro_tools.md) * [Tools](coreos/intro_tools.md)
* [Kubernetes 项目](kubernetes/README.md) * [Kubernetes](kubernetes/README.md)
* [简介](kubernetes/intro.md) * [Introduction](kubernetes/intro.md)
* [快速上手](kubernetes/quickstart.md) * [Quick start](kubernetes/quickstart.md)
* [基本概念](kubernetes/concepts.md) * [Concepts](kubernetes/concepts.md)
* [kubectl 使用](kubernetes/kubectl.md) * [kubectl](kubernetes/kubectl.md)
* [架构设计](kubernetes/design.md) * [Design](kubernetes/design.md)
* [Mesos - 优秀的集群资源调度平台](mesos/README.md) * [Cloud](cloud/README.md)
* [Mesos 简介](mesos/intro.md) * [Introduction](cloud/intro.md)
* [安装与使用](mesos/installation.md) * [AWS](cloud/aws.md)
* [原理与架构](mesos/architecture.md) * [Tencent Cloud](cloud/tencentCloud.md)
* [Mesos 配置项解析](mesos/configuration.md) * [Alibaba Cloud](cloud/alicloud.md)
* [日志与监控](mesos/monitor.md) * [SUMMARY](cloud/summary.md)
* [常见应用框架](mesos/framework.md) * [OS](cases/os/README.md)
* [本章小结](mesos/summary.md)
* [容器与云计算](cloud/README.md)
* [简介](cloud/intro.md)
* [亚马逊云](cloud/aws.md)
* [腾讯云](cloud/tencentCloud.md)
* [阿里云](cloud/alicloud.md)
* [小结](cloud/summary.md)
* [实战案例-操作系统](cases/os/README.md)
* [Busybox](cases/os/busybox.md) * [Busybox](cases/os/busybox.md)
* [Alpine](cases/os/alpine.md) * [Alpine](cases/os/alpine.md)
* [Debian Ubuntu](cases/os/debian.md) * [Debian Ubuntu](cases/os/debian.md)
* [CentOS Fedora](cases/os/centos.md) * [CentOS Fedora](cases/os/centos.md)
* [本章小结](cases/os/summary.md) * [SUMMARY](cases/os/summary.md)
* [实战案例-CI/CD](cases/ci/README.md) * [CI/CD](cases/ci/README.md)
* [GitHub Actions](cases/ci/actions/README.md) * [GitHub Actions](cases/ci/actions/README.md)
* [Drone](cases/ci/drone/README.md) * [Drone](cases/ci/drone/README.md)
* [部署 Drone](cases/ci/drone/install.md) * [Install Drone](cases/ci/drone/install.md)
* [Travis CI](cases/ci/travis/README.md) * [Travis CI](cases/ci/travis/README.md)
* [Docker 开源项目](opensource/README.md) * [Docker Open Source](opensource/README.md)
* [LinuxKit](opensource/linuxkit.md) * [LinuxKit](opensource/linuxkit.md)
* [附录](appendix/README.md) * [Appendix](appendix/README.md)
* [附录一常见问题总结](appendix/faq/README.md) * [FAQ](appendix/faq/README.md)
* [附录二热门镜像介绍](appendix/repo/README.md) * [Sample Docker Image](appendix/repo/README.md)
* [Ubuntu](appendix/repo/ubuntu.md) * [Ubuntu](appendix/repo/ubuntu.md)
* [CentOS](appendix/repo/centos.md) * [CentOS](appendix/repo/centos.md)
* [Nginx](appendix/repo/nginx.md) * [Nginx](appendix/repo/nginx.md)
@@ -161,7 +150,6 @@
* [MongoDB](appendix/repo/mongodb.md) * [MongoDB](appendix/repo/mongodb.md)
* [Redis](appendix/repo/redis.md) * [Redis](appendix/repo/redis.md)
* [Node.js](appendix/repo/nodejs.md) * [Node.js](appendix/repo/nodejs.md)
* [附录三Docker 命令查询](appendix/command/README.md) * [Docker commands](appendix/command/README.md)
* [附录四Dockerfile 最佳实践](appendix/best_practices.md) * [Docker debug](appendix/debug.md)
* [附录五如何调试 Docker](appendix/debug.md) * [Resources](appendix/resources.md)
* [附录六资源链接](appendix/resources.md)

View File

@@ -1,344 +1 @@
# Dockerfile 最佳实践 # [Best practices for writing Dockerfiles](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/)
本附录是笔者对 Docker 官方文档中 [Best practices for writing Dockerfiles](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/) 的理解与翻译。
## 一般性的指南和建议
### 容器应该是短暂的
通过 `Dockerfile` 构建的镜像所启动的容器应该尽可能短暂生命周期短短暂意味着可以停止和销毁容器并且创建一个新容器并部署好所需的设置和配置工作量应该是极小的
### 使用 `.dockerignore` 文件
使用 `Dockerfile` 构建镜像时最好是将 `Dockerfile` 放置在一个新建的空目录下然后将构建镜像所需要的文件添加到该目录中为了提高构建镜像的效率你可以在目录下新建一个 `.dockerignore` 文件来指定要忽略的文件和目录`.dockerignore` 文件的排除模式语法和 Git `.gitignore` 文件相似
### 使用多阶段构建
`Docker 17.05` 以上版本中你可以使用 [多阶段构建](../image/multistage-builds.md) 来减少所构建镜像的大小
### 避免安装不必要的包
为了降低复杂性减少依赖减小文件大小节约构建时间你应该避免安装任何不必要的包例如不要在数据库镜像中包含一个文本编辑器
### 一个容器只运行一个进程
应该保证在一个容器中只运行一个进程将多个应用解耦到不同容器中保证了容器的横向扩展和复用例如 web 应用应该包含三个容器web应用数据库缓存
如果容器互相依赖你可以使用 [Docker 自定义网络](../network/linking.md) 来把这些容器连接起来
### 镜像层数尽可能少
你需要在 `Dockerfile` 可读性也包括长期的可维护性和减少层数之间做一个平衡
### 将多行参数排序
将多行参数按字母顺序排序比如要安装多个包时这可以帮助你避免重复包含同一个包更新包列表时也更容易也便于 `PRs` 阅读和审查建议在反斜杠符号 `\` 之前添加一个空格以增加可读性
下面是来自 `buildpack-deps` 镜像的例子
```dockerfile
RUN apt-get update && apt-get install -y \
bzr \
cvs \
git \
mercurial \
subversion
```
### 构建缓存
在镜像的构建过程中Docker 会遍历 `Dockerfile` 文件中的指令然后按顺序执行在执行每条指令之前Docker 都会在缓存中查找是否已经存在可重用的镜像如果有就使用现存的镜像不再重复创建如果你不想在构建过程中使用缓存你可以在 `docker build` 命令中使用 `--no-cache=true` 选项
但是如果你想在构建的过程中使用缓存你得明白什么时候会什么时候不会找到匹配的镜像遵循的基本规则如下
* 从一个基础镜像开始`FROM` 指令指定下一条指令将和该基础镜像的所有子镜像进行匹配检查这些子镜像被创建时使用的指令是否和被检查的指令完全一样如果不是则缓存失效
* 在大多数情况下只需要简单地对比 `Dockerfile` 中的指令和子镜像然而有些指令需要更多的检查和解释
* 对于 `ADD` `COPY` 指令镜像中对应文件的内容也会被检查每个文件都会计算出一个校验和文件的最后修改时间和最后访问时间不会纳入校验在缓存的查找过程中会将这些校验和和已存在镜像中的文件校验和进行对比如果文件有任何改变比如内容和元数据则缓存失效
* 除了 `ADD` `COPY` 指令缓存匹配过程不会查看临时容器中的文件来决定缓存是否匹配例如当执行完 `RUN apt-get -y update` 指令后容器中一些文件被更新 Docker 不会检查这些文件这种情况下只有指令字符串本身被用来匹配缓存
一旦缓存失效所有后续的 `Dockerfile` 指令都将产生新的镜像缓存不会被使用
## Dockerfile 指令
下面针对 `Dockerfile` 中各种指令的最佳编写方式给出建议
### FROM
尽可能使用当前官方仓库作为你构建镜像的基础推荐使用 [Alpine](https://hub.docker.com/_/alpine/) 镜像,因为它被严格控制并保持最小尺寸(目前小于 5 MB但它仍然是一个完整的发行版。
### LABEL
你可以给镜像添加标签来帮助组织镜像记录许可信息辅助自动化构建等每个标签一行 `LABEL` 开头加上一个或多个标签对下面的示例展示了各种不同的可能格式`#` 开头的行是注释内容
>注意如果你的字符串中包含空格必须将字符串放入引号中或者对空格使用转义如果字符串内容本身就包含引号必须对引号使用转义
```dockerfile
# Set one or more individual labels
LABEL com.example.version="0.0.1-beta"
LABEL vendor="ACME Incorporated"
LABEL com.example.release-date="2015-02-12"
LABEL com.example.version.is-production=""
```
一个镜像可以包含多个标签但建议将多个标签放入到一个 `LABEL` 指令中
```dockerfile
# Set multiple labels at once, using line-continuation characters to break long lines
LABEL vendor=ACME\ Incorporated \
com.example.is-beta= \
com.example.is-production="" \
com.example.version="0.0.1-beta" \
com.example.release-date="2015-02-12"
```
关于标签可以接受的键值对参考 [Understanding object labels](https://docs.docker.com/config/labels-custom-metadata/)。关于查询标签信息,参考 [Managing labels on objects](https://docs.docker.com/config/labels-custom-metadata/)。
### RUN
为了保持 `Dockerfile` 文件的可读性可理解性以及可维护性建议将长的或复杂的 `RUN` 指令用反斜杠 `\` 分割成多行
#### apt-get
`RUN` 指令最常见的用法是安装包用的 `apt-get`因为 `RUN apt-get` 指令会安装包所以有几个问题需要注意
不要使用 `RUN apt-get upgrade` `dist-upgrade`因为许多基础镜像中的必须包不会在一个非特权容器中升级如果基础镜像中的某个包过时了你应该联系它的维护者如果你确定某个特定的包比如 `foo`需要升级使用 `apt-get install -y foo` 就行该指令会自动升级 `foo`
永远将 `RUN apt-get update` `apt-get install` 组合成一条 `RUN` 声明例如
```dockerfile
RUN apt-get update && apt-get install -y \
package-bar \
package-baz \
package-foo
```
`apt-get update` 放在一条单独的 `RUN` 声明中会导致缓存问题以及后续的 `apt-get install` 失败比如假设你有一个 `Dockerfile` 文件
```dockerfile
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y curl
```
构建镜像后所有的层都在 Docker 的缓存中假设你后来又修改了其中的 `apt-get install` 添加了一个包
```dockerfile
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y curl nginx
```
Docker 发现修改后的 `RUN apt-get update` 指令和之前的完全一样所以`apt-get update` 不会执行而是使用之前的缓存镜像因为 `apt-get update` 没有运行后面的 `apt-get install` 可能安装的是过时的 `curl` `nginx` 版本
使用 `RUN apt-get update && apt-get install -y` 可以确保你的 Dockerfiles 每次安装的都是包的最新的版本而且这个过程不需要进一步的编码或额外干预这项技术叫作 `cache busting`你也可以显示指定一个包的版本号来达到 `cache-busting`这就是所谓的固定版本例如
```dockerfile
RUN apt-get update && apt-get install -y \
package-bar \
package-baz \
package-foo=1.3.*
```
固定版本会迫使构建过程检索特定的版本而不管缓存中有什么这项技术也可以减少因所需包中未预料到的变化而导致的失败
下面是一个 `RUN` 指令的示例模板展示了所有关于 `apt-get` 的建议
```dockerfile
RUN apt-get update && apt-get install -y \
aufs-tools \
automake \
build-essential \
curl \
dpkg-sig \
libcap-dev \
libsqlite3-dev \
mercurial \
reprepro \
ruby1.9.1 \
ruby1.9.1-dev \
s3cmd=1.1.* \
&& rm -rf /var/lib/apt/lists/*
```
其中 `s3cmd` 指令指定了一个版本号 `1.1.*`如果之前的镜像使用的是更旧的版本指定新的版本会导致 `apt-get udpate` 缓存失效并确保安装的是新版本
另外清理掉 apt 缓存 `var/lib/apt/lists` 可以减小镜像大小因为 `RUN` 指令的开头为 `apt-get udpate`包缓存总是会在 `apt-get install` 之前刷新
> 注意官方的 Debian Ubuntu 镜像会自动运行 apt-get clean所以不需要显式的调用 apt-get clean
### CMD
`CMD` 指令用于执行目标镜像中包含的软件可以包含参数`CMD` 大多数情况下都应该以 `CMD ["executable", "param1", "param2"...]` 的形式使用因此如果创建镜像的目的是为了部署某个服务(比如 `Apache`)你可能会执行类似于 `CMD ["apache2", "-DFOREGROUND"]` 形式的命令我们建议任何服务镜像都使用这种形式的命令
多数情况下`CMD` 都需要一个交互式的 `shell` (bash, Python, perl )例如 `CMD ["perl", "-de0"]`或者 `CMD ["PHP", "-a"]`使用这种形式意味着当你执行类似 `docker run -it python` 你会进入一个准备好的 `shell` `CMD` 应该在极少的情况下才能以 `CMD ["param", "param"]` 的形式与 `ENTRYPOINT` 协同使用除非你和你的镜像使用者都对 `ENTRYPOINT` 的工作方式十分熟悉
### EXPOSE
`EXPOSE` 指令用于指定容器将要监听的端口因此你应该为你的应用程序使用常见的端口例如提供 `Apache` web 服务的镜像应该使用 `EXPOSE 80`而提供 `MongoDB` 服务的镜像使用 `EXPOSE 27017`
对于外部访问用户可以在执行 `docker run` 时使用一个标志来指示如何将指定的端口映射到所选择的端口
### ENV
为了方便新程序运行你可以使用 `ENV` 来为容器中安装的程序更新 `PATH` 环境变量例如使用 `ENV PATH /usr/local/nginx/bin:$PATH` 来确保 `CMD ["nginx"]` 能正确运行
`ENV` 指令也可用于为你想要容器化的服务提供必要的环境变量比如 Postgres 需要的 `PGDATA`
最后`ENV` 也能用于设置常见的版本号比如下面的示例
```dockerfile
ENV PG_MAJOR 9.3
ENV PG_VERSION 9.3.4
RUN curl -SL http://example.com/postgres-$PG_VERSION.tar.xz | tar -xJC /usr/src/postgress && …
ENV PATH /usr/local/postgres-$PG_MAJOR/bin:$PATH
```
类似于程序中的常量这种方法可以让你只需改变 `ENV` 指令来自动的改变容器中的软件版本
### ADD COPY
虽然 `ADD` `COPY` 功能类似但一般优先使用 `COPY`因为它比 `ADD` 更透明`COPY` 只支持简单将本地文件拷贝到容器中 `ADD` 有一些并不明显的功能比如本地 tar 提取和远程 URL 支持因此`ADD` 的最佳用例是将本地 tar 文件自动提取到镜像中例如 `ADD rootfs.tar.xz`
如果你的 `Dockerfile` 有多个步骤需要使用上下文中不同的文件单独 `COPY` 每个文件而不是一次性的 `COPY` 所有文件这将保证每个步骤的构建缓存只在特定的文件变化时失效例如
```dockerfile
COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt
COPY . /tmp/
```
如果将 `COPY . /tmp/` 放置在 `RUN` 指令之前只要 `.` 目录中任何一个文件变化都会导致后续指令的缓存失效
为了让镜像尽量小最好不要使用 `ADD` 指令从远程 URL 获取包而是使用 `curl` `wget`这样你可以在文件提取完之后删掉不再需要的文件来避免在镜像中额外添加一层比如尽量避免下面的用法
```dockerfile
ADD http://example.com/big.tar.xz /usr/src/things/
RUN tar -xJf /usr/src/things/big.tar.xz -C /usr/src/things
RUN make -C /usr/src/things all
```
而是应该使用下面这种方法
```dockerfile
RUN mkdir -p /usr/src/things \
&& curl -SL http://example.com/big.tar.xz \
| tar -xJC /usr/src/things \
&& make -C /usr/src/things all
```
上面使用的管道操作所以没有中间文件需要删除
对于其他不需要 `ADD` 的自动提取功能的文件或目录你应该使用 `COPY`
### ENTRYPOINT
`ENTRYPOINT` 的最佳用处是设置镜像的主命令允许将镜像当成命令本身来运行 `CMD` 提供默认选项
例如下面的示例镜像提供了命令行工具 `s3cmd`:
```dockerfile
ENTRYPOINT ["s3cmd"]
CMD ["--help"]
```
现在直接运行该镜像创建的容器会显示命令帮助
```bash
$ docker run s3cmd
```
或者提供正确的参数来执行某个命令
```bash
$ docker run s3cmd ls s3://mybucket
```
这样镜像名可以当成命令行的参考
`ENTRYPOINT` 指令也可以结合一个辅助脚本使用和前面命令行风格类似即使启动工具需要不止一个步骤
例如`Postgres` 官方镜像使用下面的脚本作为 `ENTRYPOINT`
```bash
#!/bin/bash
set -e
if [ "$1" = 'postgres' ]; then
chown -R postgres "$PGDATA"
if [ -z "$(ls -A "$PGDATA")" ]; then
gosu postgres initdb
fi
exec gosu postgres "$@"
fi
exec "$@"
```
>注意该脚本使用了 Bash 的内置命令 exec所以最后运行的进程就是容器的 PID 1 的进程这样进程就可以接收到任何发送给容器的 Unix 信号了
该辅助脚本被拷贝到容器并在容器启动时通过 `ENTRYPOINT` 执行
```dockerfile
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
```
该脚本可以让用户用几种不同的方式和 `Postgres` 交互
你可以很简单地启动 `Postgres`
```bash
$ docker run postgres
```
也可以执行 `Postgres` 并传递参数
```bash
$ docker run postgres postgres --help
```
最后你还可以启动另外一个完全不同的工具比如 `Bash`
```bash
$ docker run --rm -it postgres bash
```
### VOLUME
`VOLUME` 指令用于暴露任何数据库存储文件配置文件或容器创建的文件和目录强烈建议使用 `VOLUME` 来管理镜像中的可变部分和用户可以改变的部分
### USER
如果某个服务不需要特权执行建议使用 `USER` 指令切换到非 root 用户先在 `Dockerfile` 中使用类似 `RUN groupadd -r postgres && useradd -r -g postgres postgres` 的指令创建用户和用户组
>注意在镜像中用户和用户组每次被分配的 UID/GID 都是不确定的下次重新构建镜像时被分配到的 UID/GID 可能会不一样如果要依赖确定的 UID/GID你应该显示的指定一个 UID/GID
你应该避免使用 `sudo`因为它不可预期的 TTY 和信号转发行为可能造成的问题比它能解决的问题还多如果你真的需要和 `sudo` 类似的功能例如 root 权限初始化某个守护进程以非 root 权限执行它你可以使用 [gosu](https://github.com/tianon/gosu)。
最后为了减少层数和复杂度避免频繁地使用 `USER` 来回切换用户
### WORKDIR
为了清晰性和可靠性你应该总是在 `WORKDIR` 中使用绝对路径另外你应该使用 `WORKDIR` 来替代类似于 `RUN cd ... && do-something` 的指令后者难以阅读排错和维护
## 官方镜像示例
这些官方镜像的 Dockerfile 都是参考典范https://github.com/docker-library/docs

View File

@@ -1,7 +1,7 @@
# 基本概念 # Basic Concepts
Docker 包括三个基本概念 Docker contains 3 basic concepts
* 镜像`Image` * `Image`
* 容器`Container` * `Container`
* 仓库`Repository` * `Repository`
理解了这三个概念就理解了 Docker 的整个生命周期 Only after knowing the above 3 concepts will we get a deeper understanding of the lifecyle of docker.

View File

@@ -1,13 +1,13 @@
## Docker 容器 ## Docker Container
镜像`Image`和容器`Container`的关系就像是面向对象程序设计中的 `` `实例` 一样镜像是静态的定义容器是镜像运行时的实体容器可以被创建启动停止删除暂停等 The relationship between `Image` and `Container` is just as `Class` and `Instance` in [OOP](https://en.wikipedia.org/wiki/Object-oriented_programming). `Image` is the static definition of `container`, while `containers` are the `images` in running state. `Containers` can be created, started, paused, deleted or stopped.
容器的实质是进程但与直接在宿主执行的进程不同容器进程运行于属于自己的独立的 [命名空间](https://en.wikipedia.org/wiki/Linux_namespaces)。因此容器可以拥有自己的 `root` 文件系统、自己的网络配置、自己的进程空间,甚至自己的用户 ID 空间。容器内的进程是运行在一个隔离的环境里,使用起来,就好像是在一个独立于宿主的系统下操作一样。这种特性使得容器封装的应用比直接在宿主运行更加安全。也因为这种隔离的特性,很多人初学 Docker 时常常会混淆容器和虚拟机。 The essence of `container` is `process`, but different from that in the host OS, the container processes run in their individual [`namespaces`](https://en.wikipedia.org/wiki/Linux_namespaces). With the namespace, a container can have its own `root` filesystem, network configurations, process space and even an ID space for users. The processes in a container run in an isolated environment, thus can be used as if it were an individual OS independent of the host OS. This feature makes docker-encapsulated applications safer than those running directly on the host. And that's also an important factor that confuses the novices to tell it from virtual machines.
前面讲过镜像使用的是分层存储容器也是如此每一个容器运行时是以镜像为基础层在其上创建一个当前容器的存储层我们可以称这个为容器运行时读写而准备的存储层为 **容器存储层** As we've discussed, `multi-layered filesystem` is applied to images, and so as the containers. When a container is running, it is based on its image, with a writable layer created on top of it. We call this layer prepared for R/W at runtime [**`Container Layer`**](https://docs.docker.com/storage/storagedriver/#images-and-layers).
容器存储层的生存周期和容器一样容器消亡时容器存储层也随之消亡因此任何保存于容器存储层的信息都会随容器删除而丢失 The lifecyle of the container layer is the same as contaier. The container layer dies as soon as the container dies. Therefore, anything stored at the container layer will be discarded when the container is deleted.
按照 Docker 最佳实践的要求容器不应该向其存储层内写入任何数据容器存储层要保持无状态化所有的文件写入操作都应该使用 [数据卷Volume](../data_management/volume.md)或者绑定宿主目录在这些位置的读写会跳过容器存储层直接对宿主或网络存储发生读写其性能和稳定性更高 As recommended by the [Docker Development Best Practices](https://docs.docker.com/develop/dev-best-practices/#where-and-how-to-persist-application-data), we should not write any data to the container layer to make it stateless. All file write operations should adhere to [`Volume`](../data_management/volume.md) or bind mounts. Writing to volume or bind mounts skips the container layer and R/W to host storage(or network storage) directly, which achieves better performance and stability.
数据卷的生存周期独立于容器容器消亡数据卷不会消亡因此使用数据卷后容器删除或者重新运行之后数据却不会丢失 The lifecyle of volume is independent of the container, and will not vanish when the container is deleted. In light of it, the data persists when a container is deleted or restarted.

View File

@@ -1,15 +1,15 @@
## Docker 镜像 ## Docker Image
我们都知道操作系统分为内核和用户空间对于 Linux 而言内核启动后会挂载 `root` 文件系统为其提供用户空间支持 Docker 镜像Image就相当于是一个 `root` 文件系统比如官方镜像 `ubuntu:18.04` 就包含了完整的一套 Ubuntu 18.04 最小系统的 `root` 文件系统 As we all know, Operating System consists of kernel space and user space. For linux, it will mount `root` filesystem to support user space. For Docker Image, it is similar to a `root` filesystem in Linux. For example, the offical image `ubuntu:18:04` contains a micro `root` filesystem of complete opreating system.
Docker 镜像是一个特殊的文件系统除了提供容器运行时所需的程序资源配置等文件外还包含了一些为运行时准备的一些配置参数如匿名卷环境变量用户等镜像不包含任何动态数据其内容在构建之后也不会被改变 Docker Image is a special filesystem. Apart from programs, libs, resources and config which support running container, Docker Image also includes config parameters like anonymous volumes, environment variables, users and others. Images don't have any dynamic data. Its content will not be changed after build.
### 分层存储 ## Advanced Multi-layered Unification Filesystem (AUFS)
因为镜像包含操作系统完整的 `root` 文件系统其体积往往是庞大的因此在 Docker 设计时就充分利用 [Union FS](https://en.wikipedia.org/wiki/Union_mount) 的技术,将其设计为分层存储的架构。所以严格来说,镜像并非是像一个 ISO 那样的打包文件,镜像只是一个虚拟的概念,其实际体现并非由一个文件组成,而是由一组文件系统组成,或者说,由多层文件系统联合组成。 Because the image contains the complete `root` file system of the operating system, its volume is often huge. So Docker made full use of [Union FS](https://en.wikipedia.org/wiki/Union_mount) and was designed as AUFS when it was designed. So strictly speaking, image is not a packaged file like an ISO image file. Image is just a virtual concept. It is not composed of a single file, but a group of file systems, or a combination of multi-layered filesystems.
镜像构建时会一层层构建前一层是后一层的基础每一层构建完就不会再发生改变后一层上的任何改变只发生在自己这一层比如删除前一层文件的操作实际不是真的删除前一层的文件而是仅在当前层标记为该文件已删除在最终容器运行的时候虽然不会看到这个文件但是实际上该文件会一直跟随镜像因此在构建镜像的时候需要额外小心每一层尽量只包含该层需要添加的东西任何额外的东西应该在该层构建结束前清理掉 When building an image, it builds layer by layer, and the former is the basis for the latter. Once each layer is built, it will not change later. Any change on the latter layer will only occur on its own level. For example, deleting the previous layer of files is not really deleting the files, but only marked as deleted in the current layer. When the final container runs, you won't see the file, but in fact the file will always follow the image. Therefore, take more care when building the image, and any redundant file should be cleared up in ahead of the layer's final construction.
分层存储的特征还使得镜像的复用定制变的更为容易甚至可以用之前构建好的镜像作为基础层然后进一步添加新的层以定制自己所需的内容构建新的镜像 The layered storage feature also makes it easier to reuse and customize images. You can even use a previously built image as the base layer, and then add a new layer to customize the content to meet your need to build a new image.
关于镜像构建将会在后续相关章节中做进一步的讲解 As for image building, further explanations will be given in subsequent relevant chapters.

View File

@@ -1,29 +1,29 @@
## Docker Registry ## Docker Registry
镜像构建完成后可以很容易的在当前宿主机上运行但是如果需要在其它服务器上使用这个镜像我们就需要一个集中的存储分发镜像的服务[Docker Registry](../repository/registry.md) 就是这样的服务 After the construction of an image, we can easily run it on a host. However, if we want to use the image on other servers, we need a centralized image storage and distribution service. The [Docker Registry](../repository/registry.md) we will introduce is such a service.
一个 **Docker Registry** 中可以包含多个 **仓库**`Repository`每个仓库可以包含多个 **标签**`Tag`每个标签对应一个镜像 A **Docker Registry** can contain several `Repositories`, where each repository can contain several tags and each tag corresponds to an image.
通常一个仓库会包含同一个软件不同版本的镜像而标签就常用于对应该软件的各个版本我们可以通过 `<仓库名>:<标签>` 的格式来指定具体是这个软件哪个版本的镜像如果不给出标签将以 `latest` 作为默认标签 Typically, a repository contains images for different versions of the same software, where each tags corresponds to different versions of the software. We can uniquely identify an image of the same software with `repository:tag`. In case not explicitly specified, `latest` is taken as default tag.
[Ubuntu 镜像](https://hub.docker.com/_/ubuntu) 为例,`ubuntu` 是仓库的名字,其内包含有不同的版本标签,如,`16.04`, `18.04`。我们可以通过 `ubuntu:16.04`,或者 `ubuntu:18.04` 来具体指定所需哪个版本的镜像。如果忽略了标签,比如 `ubuntu`,那将视为 `ubuntu:latest` Taking the [Ubuntu Image](https://hub.docker.com/_/ubuntu) as an example. `ubuntu` is the name for repository, and inside it are tags for different versions, for instance, `16.04`, `18.04`. We can use `ubuntu:16.04` or `ubuntu:18.04` to specify the particular image we want. If the tag is omitted, for example, `ubuntu`, then it will be considered as `ubuntu:latest`.
仓库名经常以 *两段式路径* 形式出现比如 `jwilder/nginx-proxy`前者往往意味着 Docker Registry 多用户环境下的用户名后者则往往是对应的软件名但这并非绝对取决于所使用的具体 Docker Registry 的软件或服务 Repository name is typically seperated by a forward slash(/), for example, `jwilder/nginx-proxy`, the former is to identify a particular user in a multi-user Docker Registry, while the latter corresponds to the software name. But it is not always the case. It also depends on the Docker Registry software or service you are using.
### Docker Registry 公开服务 ### Docker Registry Public Services
Docker Registry 公开服务是开放给用户使用允许用户管理镜像的 Registry 服务一般这类公开服务允许用户免费上传下载公开的镜像并可能提供收费服务供用户管理私有镜像 `Docker Registry Public Services` are registry services open to users, allowing users to manage their images. Typically, those public services offer user free image uploads and downloads, and possibly provide charged service for privately managed images.
最常使用的 Registry 公开服务是官方的 [Docker Hub](https://hub.docker.com/),这也是默认的 Registry并拥有大量的高质量的官方镜像。除此以外还有 [CoreOS](https://coreos.com/) 的 [Quay.io](https://quay.io/repository/)CoreOS 相关的镜像存储在这里;Google [Google Container Registry](https://cloud.google.com/container-registry/)[Kubernetes](https://kubernetes.io/) 的镜像使用的就是这个服务。 The most commonly used registry public service is the official [Docker Hub](https://hub.docker.com/), which is the default registry with thousands of high quality official images. Besides, the images for [Quay.io](https://quay.io/repository/) and CoreOS of [CoreOS](https://coreos.com/) are stored there. Google's [Google Container Registry](https://cloud.google.com/container-registry/) and [Kubernetes](https://kubernetes.io/) also use this service.
由于某些原因在国内访问这些服务可能会比较慢国内的一些云服务商提供了针对 Docker Hub 的镜像服务`Registry Mirror`这些镜像服务被称为**加速器**常见的有 [阿里云加速器](https://cr.console.aliyun.com/#/accelerator)[DaoCloud 加速器](https://www.daocloud.io/mirror#accelerator-doc) 等。使用加速器会直接从国内的地址下载 Docker Hub 的镜像,比直接从 Docker Hub 下载速度会提高很多。在 [安装 Docker](../install/mirror.md) 一节中有详细的配置方法。 Due to some reasons knwon to all, accessing those services from China mainland is slow. There are some cloud service providers in China providing `Registry Mirror` for Docker Hub, those mirror services are called `accelerators`. The well-known ones are [Ali Cloud Image Accelerator](https://cr.console.aliyun.com/#/accelerator) and [DaoCloud Accelerator](https://www.daocloud.io/mirror#accelerator-doc). In China, downloading from these services are much faster than from Docker Hub. The detailed image source configuration tutorial is in the [Docker Installation](../install/mirror.md) section.
国内也有一些云服务商提供类似于 Docker Hub 的公开服务比如 [时速云镜像仓库](https://hub.tenxcloud.com/)、[网易云镜像服务](https://c.163.com/hub#/m/library/)[DaoCloud 镜像市场](https://hub.daocloud.io/)、[阿里云镜像库](https://cr.console.aliyun.com) 等。 There are also some cloud service providers that provide public services similar to Docker Hub in China. For example, [Tenxcloud Mirror Registry](https://hub.tenxcloud.com/), [NetEase Mirror Registry](https://c.163.com/hub#/m/library/), [DaoCloud Mirror Market](https://hub.daocloud.io/), [Ali Cloud Mirror Registry](https://cr.console.aliyun.com), etc.
### 私有 Docker Registry ### Private Docker Registry
除了使用公开服务外用户还可以在本地搭建私有 Docker RegistryDocker 官方提供了 [Docker Registry](https://hub.docker.com/_/registry/) 镜像,可以直接使用做为私有 Registry 服务。在 [私有仓库](../repository/registry.md) 一节中,会有进一步的搭建私有 Registry 服务的讲解。 Apart from using public service, a user can set up private Docker Registry. Docker offical offers the [Docker Registry](https://hub.docker.com/_/registry/) docker image, which can be deployed for private registry service. We will explain how to set it up in detail in the [Private Registry](../repository/registry.md) section.
开源的 Docker Registry 镜像只提供了 [Docker Registry API](https://docs.docker.com/registry/spec/api/) 的服务端实现,足以支持 `docker` 命令,不影响使用。但不包含图形界面,以及镜像维护、用户管理、访问控制等高级功能。在官方的商业化版本 [Docker Trusted Registry](https://docs.docker.com/datacenter/dtr/2.0/) 中,提供了这些高级功能。 The open source Docker Registry image only provides the backend of [Docker Registry API](https://docs.docker.com/registry/spec/api/), which supports the `docker` commands and is enough for personal use, although the advanced functionalities like GUI(Graphical User Interface), Image Maintenance and Access Control are not supported. However, they are provided in the commercial version - [Docker Trusted Registry](https://docs.docker.com/datacenter/dtr/2.0/).
除了官方的 Docker Registry 还有第三方软件实现了 Docker Registry API甚至提供了用户界面以及一些高级功能比如[Harbor](https://github.com/goharbor/harbor) [Sonatype Nexus](../repository/nexus3_registry.md) Except for the official Docker Registry, there are third-party softwares that implement Docker Registry API, even with some advanced features like user interface. For example, [Harbor](https://github.com/goharbor/harbor) and [Sonatype Nexus](../repository/nexus3_registry.md).

View File

@@ -1,7 +1,7 @@
{ {
"title": "Docker -- 从入门到实践", "title": "Docker Practice",
"author": "yeasy", "author": "yeasy",
"language": "zh-hans", "language": "en",
"links": { "links": {
"sidebar": { "sidebar": {
"GitHub": "https://github.com/yeasy/docker_practice" "GitHub": "https://github.com/yeasy/docker_practice"
@@ -19,14 +19,13 @@
"attributes": { "attributes": {
"width": "600" "width": "600"
}, },
"caption": " _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_ - _CAPTION_" "caption": "Image _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_ - _CAPTION_"
}, },
"github": { "github": {
"url": "https://github.com/yeasy/docker_practice" "url": "https://github.com/yeasy/docker_practice"
}, },
"editlink": { "editlink": {
"base": "https://github.com/yeasy/docker_practice/blob/master/", "base": "https://github.com/yeasy/docker_practice/blob/english/"
"label": "编辑本页"
}, },
"page-treeview": { "page-treeview": {
"copyright": "Copyright &#169; yeasy", "copyright": "Copyright &#169; yeasy",

View File

@@ -1,13 +1,13 @@
# 使用 Docker 镜像 # Use Docker Images
在之前的介绍中我们知道镜像是 Docker 的三大组件之一 As we have introduced before, `image` is one of the 3 major components of Docker.
Docker 运行容器前需要本地存在对应的镜像如果本地不存在该镜像Docker 会从镜像仓库下载该镜像 Upon running docker container, it can run local image or if the image is not locally available, it will download from a registry.
本章将介绍更多关于镜像的内容包括 In this chapter we will introduce more about `image`, including
* 从仓库获取镜像 * Pull images from registry
* 管理本地主机上的镜像 * Manage local images
* 介绍镜像实现的基本原理 * The mechanisms and implementaion of images

View File

@@ -1,6 +1,6 @@
## 列出镜像 ## List all Images
要想列出已经下载下来的镜像可以使用 `docker image ls` 命令 If you want to list all the images downloaded, you can use the command `docker image ls` or `docker images`.
```bash ```bash
$ docker image ls $ docker image ls
@@ -13,17 +13,17 @@ ubuntu 18.04 f753707788c5 4 weeks ago
ubuntu latest f753707788c5 4 weeks ago 127 MB ubuntu latest f753707788c5 4 weeks ago 127 MB
``` ```
列表包含了 `仓库名``标签``镜像 ID``创建时间` 以及 `所占用的空间` You can see `Repository`, `Tag`, `Image ID`, `Created` and `Size` from the list.
其中仓库名标签在之前的基础概念章节已经介绍过了**镜像 ID** 则是镜像的唯一标识一个镜像可以对应多个 **标签**因此在上面的例子中我们可以看到 `ubuntu:18.04` `ubuntu:latest` 拥有相同的 ID因为它们对应的是同一个镜像 Among these, the repository name and tag have been introduced in the basic concepts chapter. **Image ID** is the unique identifier for the image, and an image can correspond to multiple **labels**. In the exmaple above, we can see `ubuntu:18:04` and `ubuntu:latest` having the same ID, since they are aliases for the same image.
### 镜像体积 ### Image Size
如果仔细观察会注意到这里标识的所占用空间和在 Docker Hub 上看到的镜像大小不同比如`ubuntu:18.04` 镜像大小在这里是 `127 MB`但是在 [Docker Hub](https://hub.docker.com/r/library/ubuntu/tags/) 显示的却是 `50 MB`。这是因为 Docker Hub 中显示的体积是压缩后的体积。在镜像下载和上传过程中镜像是保持着压缩状态的,因此 Docker Hub 所显示的大小是网络传输中更关心的流量大小。而 `docker image ls` 显示的是镜像下载到本地后,展开的大小,准确说,是展开后的各层所占空间的总和,因为镜像到本地后,查看空间的时候,更关心的是本地磁盘空间占用的大小。 If you pay close attention to all of these. You may find that the disk space they occupy is different from the one at Docker Hub. For example, `ubuntu:18.04` is `127MB` here, but on [Docker Hub](https://hub.docker.com/r/library/ubuntu/tags/), `50MB` is displayed. That's because what is shown on Docker Hub is the size after compression. During image download and upload, the image is compressed, because the data transfer is the main factor taken into consideration. However, when we use the command `docker image ls`, that's the size after expansion. To be more precisely, the total size after expanding all the layers locally, because we care more about local space occupied when an image is on our disk.
另外一个需要注意的问题是`docker image ls` 列表中的镜像体积总和并非是所有镜像实际硬盘消耗由于 Docker 镜像是多层存储结构并且可以继承复用因此不同镜像可能会因为使用相同的基础镜像从而拥有共同的层由于 Docker 使用 Union FS相同的层只需要保存一份即可因此实际镜像硬盘占用空间很可能要比这个列表镜像大小的总和要小的多 One more thing to note is that in the `docker image ls` list, the total size of images is far less than the actual size. Since the Docker imags are stored in multiple layers, and there are inheritance and reuse, there might be different images using the same basic images and sharing some common layers. As we have mentioned, Docker uses Union FS, we only keep one copy for the same layers, so the actual space occupied is far less than the mere sum.
你可以通过以下命令来便捷的查看镜像容器数据卷所占用的空间 You can use the following command to see the space utilized by images, containers, data volumes.
```bash ```bash
$ docker system df $ docker system df
@@ -35,15 +35,15 @@ Local Volumes 9 0 652.2MB
Build Cache 0B 0B Build Cache 0B 0B
``` ```
### 虚悬镜像 ### Dangling Image
上面的镜像列表中还可以看到一个特殊的镜像这个镜像既没有仓库名也没有标签均为 `<none>` In the image list above, we can see a special image, the one without repository name nor tag, all being `<none>`:
```bash ```bash
<none> <none> 00285df0df87 5 days ago 342 MB <none> <none> 00285df0df87 5 days ago 342 MB
``` ```
这个镜像原本是有镜像名和标签的原来为 `mongo:3.2`随着官方镜像维护发布了新版本后重新 `docker pull mongo:3.2` `mongo:3.2` 这个镜像名被转移到了新下载的镜像身上而旧的镜像上的这个名称则被取消从而成为了 `<none>`除了 `docker pull` 可能导致这种情况`docker build` 也同样可以导致这种现象由于新旧镜像同名旧镜像名称被取消从而出现仓库名标签均为 `<none>` 的镜像这类无标签镜像也被称为 **虚悬镜像(dangling image)** 可以用下面的命令专门显示这类镜像 This image is originally with name and tag(`mongo:3.2`). As the official image being maintained, and the release of new versions, when we execute `docker pull mongo:3.2`, the tag `mongo:3.2` is transferred to the new iamge, and the name on the old image is canceled, end up being `<none>`. Besides, `docker pull`, `docker build` might also cause this phenomemon. Because the new and old image are of the same name, the name of the old image is canceled, thus causing the repository and tag both being `<none>`. These images without tags are also called **dangling images**, we can use the following commands to show them:
```bash ```bash
$ docker image ls -f dangling=true $ docker image ls -f dangling=true
@@ -51,27 +51,27 @@ REPOSITORY TAG IMAGE ID CREATED
<none> <none> 00285df0df87 5 days ago 342 MB <none> <none> 00285df0df87 5 days ago 342 MB
``` ```
一般来说虚悬镜像已经失去了存在的价值是可以随意删除的可以用下面的命令删除 Generally speaking, the dangling images are useless, we can remove them with the following commands with ease:
```bash ```bash
$ docker image prune $ docker image prune
``` ```
### 中间层镜像 ### Intermediate Layer Images
为了加速镜像构建重复利用资源Docker 会利用 **中间层镜像**所以在使用一段时间后可能会看到一些依赖的中间层镜像默认的 `docker image ls` 列表中只会显示顶层镜像如果希望显示包括中间层镜像在内的所有镜像的话需要加 `-a` 参数 To accelerate the build of images and improve the resource utilization, Docker uses **Intermediate Layer Images**. So after using Docker for a while, you may see a list of intermediate images as dependencies. The default `docker image ls` only shows the top images, if you want to show all the images including intermediate images, you need to add the `-a` paramter.
```bash ```bash
$ docker image ls -a $ docker image ls -a
``` ```
这样会看到很多无标签的镜像与之前的虚悬镜像不同这些无标签的镜像很多都是中间层镜像是其它镜像所依赖的镜像这些无标签镜像不应该删除否则会导致上层镜像因为依赖丢失而出错实际上这些镜像也没必要删除因为之前说过相同的层只会存一遍而这些镜像是别的镜像的依赖因此并不会因为它们被列出来而多存了一份无论如何你也会需要它们只要删除那些依赖它们的镜像后这些依赖的中间层镜像也会被连带删除 You will see a lot of images without tags with this command. Differing from `dangling images`, these untagged images are intermediate layer images, and are what a lot of other images depend on. These untagged images should not be deleted, otherwise, it will cause missing dependencies errors for upstream images. In fact, these images are not necessary to delete, as we have mentioned, the same layers will be only stored once. These images are dependencies for other images, and their existence will not cause any redundancy, you will need them in any way. They will disappear the moment you delete all the images that reference them.
### 列出部分镜像 ### List Images Partially
不加任何参数的情况下`docker image ls` 会列出所有顶层镜像但是有时候我们只希望列出部分镜像`docker image ls` 有好几个参数可以帮助做到这个事情 Without any parameter, `docker image ls` lists all the top-level images, but sometimes we only want them partially. `docker image ls` has several parameters to help us achieve this goal.
根据仓库名列出镜像 To list images based on repository name.
```bash ```bash
$ docker image ls ubuntu $ docker image ls ubuntu
@@ -80,7 +80,7 @@ ubuntu 18.04 f753707788c5 4 weeks ago
ubuntu latest f753707788c5 4 weeks ago 127 MB ubuntu latest f753707788c5 4 weeks ago 127 MB
``` ```
列出特定的某个镜像也就是说指定仓库名和标签 To list a certain image, specifying repository name and label.
```bash ```bash
$ docker image ls ubuntu:18.04 $ docker image ls ubuntu:18.04
@@ -88,7 +88,7 @@ REPOSITORY TAG IMAGE ID CREATED
ubuntu 18.04 f753707788c5 4 weeks ago 127 MB ubuntu 18.04 f753707788c5 4 weeks ago 127 MB
``` ```
除此以外`docker image ls` 还支持强大的过滤器参数 `--filter`或者简写 `-f`之前我们已经看到了使用过滤器来列出虚悬镜像的用法它还有更多的用法比如我们希望看到在 `mongo:3.2` 之后建立的镜像可以用下面的命令 Besides, `docker image ls` supports the `--filter` parameter, or simply `-f`. As we have seen before, using filter to list dangling image, and it has more usages. For example, if we want to see images with edition after `mongo:3.2`, we can use the following command:
```bash ```bash
$ docker image ls -f since=mongo:3.2 $ docker image ls -f since=mongo:3.2
@@ -97,18 +97,18 @@ redis latest 5f515359c7f8 5 days ago
nginx latest 05a60462f8ba 5 days ago 181 MB nginx latest 05a60462f8ba 5 days ago 181 MB
``` ```
想查看某个位置之前的镜像也可以只需要把 `since` 换成 `before` 即可 If we want to see some versions of images before, we can simply replace `since` with `before`.
此外如果镜像构建时定义了 `LABEL`还可以通过 `LABEL` 来过滤 If we have defined the `LABEL` during the image build, we can also filter with the `LABEL` option.
```bash ```bash
$ docker image ls -f label=com.example.version=0.1 $ docker image ls -f label=com.example.version=0.1
... ...
``` ```
### 以特定格式显示 ### Show with Specified Format
默认情况下`docker image ls` 会输出一个完整的表格但是我们并非所有时候都会需要这些内容比如刚才删除虚悬镜像的时候我们需要利用 `docker image ls` 把所有的虚悬镜像的 ID 列出来然后才可以交给 `docker image rm` 命令作为参数来删除指定的这些镜像这个时候就用到了 `-q` 参数 By default, `docker image ls` will show a full list, but we do not need it all the time. For example, when we delete dangling images, we use `docker image ls` to list all the IDs of dangling images and then pass them over to `docker image rm` as parameters to remove the specified images. Under this circumstance, we can apply the `-q` option.
```bash ```bash
$ docker image ls -q $ docker image ls -q
@@ -121,11 +121,11 @@ f753707788c5
1e0c3dd64ccd 1e0c3dd64ccd
``` ```
`--filter` 配合 `-q` 产生出指定范围的 ID 列表然后送给另一个 `docker` 命令作为参数从而针对这组实体成批的进行某种操作的做法在 Docker 命令行使用过程中非常常见不仅仅是镜像将来我们会在各个命令中看到这类搭配以完成很强大的功能因此每次在文档看到过滤器后可以多注意一下它们的用法 `--filter` together with `-q` to generate a ID list in a specified range, and then passing them over to another `docker` command as parameter is a common practice for Docker commands. Not only for images, we will see all this kind of combinations in other kinds of commands, with them, we can achieve great functionalities. So when you see some filters while reading the documents, please pay attention to how they are used in practice.
另外一些时候我们可能只是对表格的结构不满意希望自己组织列或者不希望有标题这样方便其它程序解析结果等这就用到了 [Go 的模板语法](https://gohugo.io/templates/go-templates/) In some other occasions, we may not be content with the table structure and would like to reorganize the columns. In this case, we can use the [Go Templates](https://gohugo.io/templates/go-templates/).
比如下面的命令会直接列出镜像结果并且只包含镜像ID和仓库名 For example, using the following commands will list the image results, with only image ID and repository names.
```bash ```bash
$ docker image ls --format "{{.ID}}: {{.Repository}}" $ docker image ls --format "{{.ID}}: {{.Repository}}"
@@ -138,7 +138,7 @@ f753707788c5: ubuntu
1e0c3dd64ccd: ubuntu 1e0c3dd64ccd: ubuntu
``` ```
或者打算以表格等距显示并且有标题行和默认一样不过自己定义列 Or we may want to show the table with equal horizontal tabulations and with title, we can define them by ourselves.
```bash ```bash
$ docker image ls --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}" $ docker image ls --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"

View File

@@ -1,19 +1,20 @@
## 获取镜像 ## Pull Docker Images
之前提到过[Docker Hub](https://hub.docker.com/explore/) 上有大量的高质量的镜像可以用,这里我们就说一下怎么获取这些镜像。 As we have mentioned, there are many high quality docker images on [Docker Hub](https://hub.docker.com/explore/). In this section, we will introduce how to `pull` these images.
Docker 镜像仓库获取镜像的命令是 `docker pull`其命令格式为 The command to fetch image from docker registry is `docker pull`. The command format is:
```bash ```bash
docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签] docker pull [OPTIONS] [Docker Registry ADDRESS[:PORT]/]NAME[:TAG]
``` ```
具体的选项可以通过 `docker pull --help` 命令看到这里我们说一下镜像名称的格式 More options can be found by `docker pull --help` command. Now let us see the format for image names.
* Docker 镜像仓库地址地址的格式一般是 `<域名/IP>[:端口号]`默认地址是 Docker Hub * Docker Repository Address: the address format is typically `<domain/IP>[:PORT]`. The default address is Docker Hub.
* 仓库名如之前所说这里的仓库名是两段式名称 `<用户名>/<软件名>`对于 Docker Hub如果不给出用户名则默认为 `library`也就是官方镜像
比如 * Repository: as mentioned before, the repository name consists of 2 parts, i.e., `username/software-name`(separated by the slash). For docker Hub, if the username is not specified, the default is `library`, where all the official images are in.
For example,
```bash ```bash
$ docker pull ubuntu:18.04 $ docker pull ubuntu:18.04
@@ -27,17 +28,17 @@ Digest: sha256:147913621d9cdea08853f6ba9116c2e27a3ceffecf3b492983ae97c3d643fbbe
Status: Downloaded newer image for ubuntu:18.04 Status: Downloaded newer image for ubuntu:18.04
``` ```
上面的命令中没有给出 Docker 镜像仓库地址因此将会从 Docker Hub 获取镜像而镜像名称是 `ubuntu:18.04`因此将会获取官方镜像 `library/ubuntu` 仓库中标签为 `18.04` 的镜像 The Docker image repository is not given, so it will pull the image from Docker Hub. Since the image name is `ubuntu:18.04`, so it will get the official image with tag `18.04` from `library/ubuntu`.
从下载过程中可以看到我们之前提及的分层存储的概念镜像是由多层存储所构成下载也是一层层的去下载并非单一文件下载过程中给出了每一层的 ID 的前 12 并且下载结束后给出该镜像完整的 `sha256` 的摘要以确保下载一致性 From the download log, we can see the layered storage concept - images are composed of multiple layers of storage. And we download images layer by layer instead of a single file. During the download process, the first 12 hexadecimal bits of each layer are shown. And after the download, the `sha256` summary is given, to verify the integrity of downloaded files.
在使用上面命令的时候你可能会发现你所看到的层 ID 以及 `sha256` 的摘要和这里的不一样这是因为官方镜像是一直在维护的有任何新的 bug或者版本更新都会进行修复再以原来的标签发布这样可以确保任何使用这个标签的用户可以获得更安全更稳定的镜像 When using the above command, you may find that the layer ID and `sha256` you see are different from what they are here, because the official layer is maintained and updated frequently. In case there is any new bug or new edition, the image will be rebuilt and published with the original tag. This makes sure that all the users use safer and more stable images.
*如果从 Docker Hub 下载镜像非常缓慢可以参照 [镜像加速器](/install/mirror.md) 一节配置加速器* *If it is slow to download images from Docker Hub, you can refer to [Image Accelerators](/install/mirror.md) to configure accelerator.*
### 运行 ### Run
With the image, we can run a container based on the image. Taking the above `ubuntu:18.04` as an example, if we want to start the `bash` inside it for interactive operations, we can execute the following commands.
有了镜像后我们就能够以这个镜像为基础启动并运行一个容器以上面的 `ubuntu:18.04` 为例如果我们打算启动里面的 `bash` 并且进行交互式操作的话可以执行下面的命令
```bash ```bash
$ docker run -it --rm \ $ docker run -it --rm \
@@ -59,13 +60,16 @@ VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic UBUNTU_CODENAME=bionic
``` ```
`docker run` 就是运行容器的命令具体格式我们会在 [容器](../container) 一节进行详细讲解我们这里简要的说明一下上面用到的参数 `docker run` is the command for running the container, the detailed format will be explained in the [container](../container) chapter. Here we only illustrate the parameters used above.
* `-it`这是两个参数一个是 `-i`交互式操作一个是 `-t` 终端我们这里打算进入 `bash` 执行一些命令并查看返回结果因此我们需要交互式终端 * `-it`: There are 2 parameters here, the first is `-i`, for interactive operations, another is `-t`, which is for terminal. What we intend to do is to enter the `bash` terminal of docker, then execute some commands and see the output. That's why we need the interactive terminal.
* `--rm`这个参数是说容器退出后随之将其删除默认情况下为了排障需求退出的容器并不会立即删除除非手动 `docker rm`我们这里只是随便执行个命令看看结果不需要排障和保留结果因此使用 `--rm` 可以避免浪费空间
* `ubuntu:18.04`这是指用 `ubuntu:18.04` 镜像为基础来启动容器
* `bash`放在镜像名后的是 **命令**这里我们希望有个交互式 Shell因此用的是 `bash`
进入容器后我们可以在 Shell 下操作执行任何所需的命令这里我们执行了 `cat /etc/os-release`这是 Linux 常用的查看当前系统版本的命令从返回的结果可以看到容器内是 `Ubuntu 18.04.1 LTS` 系统 * `--rm`: Remove the docker after stop it. In default, for troubleshooting, the docker is not removed immediately after quitting, unless manually remove it using `docker rm`. But in our case, we only test the commands and to see the resutls, we don't care much about the results, so we use `--rm` to avoid wasting space.
最后我们通过 `exit` 退出了这个容器 * `ubuntu:18.04`: use `ubuntu:18:04` as the base image to start the container.
* `bash`: What we have after the image name is **command**, since we want an interactive shell, so we use `bash` as the command here.
After entering the comainer, we can execute any command we want. Here, we executed `cat etc/os-release`, which is the commonly-used command to view the version of the current OS. We can see from the result that the container is based on `Ubuntu 18.04.1 LTS`.
In the end, we quit the container with `exit`.

View File

@@ -1,7 +1,7 @@
# 安装 Docker # Docker Installation
Docker 分为 CE EE 两大版本CE 即社区版免费支持周期 7 个月EE 即企业版强调安全付费使用支持周期 24 个月 Docker has 2 major editions, CE and EE. CE is the Community Edition(free, 7 month as a support cycle), while EE is the Enterprise Edition, which emphasizes on security, paid membership, and the support cycle is 24 months.
Docker CE 分为 **stable**, **test**, **nightly** 三个更新频道每六个月发布一个 **stable** 版本 (18.09, 19.03, 19.09...) Docker CE has 3 update channels, **stable**, **test** and **nightly**, and releases a **stable** version every other 6 months(18.09, 19.03, 19.09...).
官方网站上有各种环境下的 [安装指南](https://docs.docker.com/engine/installation/),这里主要介绍 Docker CE 在 Linux Windows 10 (PC) macOS 上的安装。 You can find the [Installation Guidance](https://docs.docker.com/engine/installation/) at the official website. We mainly introduce Docker CE installation on Linux, Windows 10(PC) and macOS here.

View File

@@ -1,16 +1,15 @@
## CentOS 安装 Docker CE ## Install Docker CE on CentOS
>警告切勿在没有配置 Docker YUM 源的情况下直接使用 yum 命令安装 Docker. > WARNING: DO NOT install Docker with yum directly without configuring yum source.
### 准备工作 ### Prerequisites
#### 系统要求 #### OS Requirement
Docker CE supports 64-bit version of CentOS 7, and it requires the kernel version to be no older than 3.10. CentOS 7 satisfies the minimum kernel version requirement. But due to the comparatively old kernel, some of the functionalities like `overlay2` are unable to be used, and some other features may be unstable.
Docker CE 支持 64 位版本 CentOS 7并且要求内核版本不低于 3.10 CentOS 7 满足最低内核的要求但由于内核版本比较低部分功能 `overlay2` 存储层驱动无法使用并且部分功能可能不太稳定 #### Uninstall the Old Versions
#### 卸载旧版本 The old versions of Docker are called `docker` or `docker-engine`, you can have them uninstalled with the following command:
旧版本的 Docker 称为 `docker` 或者 `docker-engine`使用以下命令卸载旧版本
```bash ```bash
$ sudo yum remove docker \ $ sudo yum remove docker \
@@ -25,9 +24,9 @@ $ sudo yum remove docker \
docker-engine docker-engine
``` ```
### 使用 yum 安装 ### Install with yum
执行以下命令安装依赖包 Use the following commands to install the dependencies:
```bash ```bash
$ sudo yum install -y yum-utils \ $ sudo yum install -y yum-utils \
@@ -35,80 +34,79 @@ $ sudo yum install -y yum-utils \
lvm2 lvm2
``` ```
鉴于国内网络问题强烈建议使用国内源官方源请在注释中查看 Due to the network issues in China mainland, it is highly recommended for Chinese users to use Chinese sources. Please refer to the official sources in the comments(they are replaced by a Chinese source).
执行下面的命令添加 `yum` 软件源
Use the following command to add `dnf` source.
```bash ```bash
$ sudo yum-config-manager \ $ sudo yum-config-manager \
--add-repo \ --add-repo \
https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
# 官方源 # Official source
# $ sudo yum-config-manager \ # $ sudo yum-config-manager \
# --add-repo \ # --add-repo \
# https://download.docker.com/linux/centos/docker-ce.repo # https://download.docker.com/linux/centos/docker-ce.repo
``` ```
如果需要测试版本的 Docker CE 请使用以下命令 If you want to use the `test` version of Docker CE, use the following command:
```bash ```bash
$ sudo yum-config-manager --enable docker-ce-test $ sudo yum-config-manager --enable docker-ce-test
``` ```
如果需要每日构建版本的 Docker CE 请使用以下命令 As for `nightly` version:
```bash ```bash
$ sudo yum-config-manager --enable docker-ce-nightly $ sudo yum-config-manager --enable docker-ce-nightly
``` ```
#### 安装 Docker CE #### Install Docker CE
更新 `yum` 软件源缓存并安装 `docker-ce` Update `yum` source cacheand then install `docker-ce`.
```bash ```bash
$ sudo yum makecache fast $ sudo yum makecache fast
$ sudo yum install docker-ce $ sudo yum install docker-ce
``` ```
### 使用脚本自动安装 ### Install with Automatic Scripts
在测试或开发环境中 Docker 官方为了简化安装流程提供了一套便捷的安装脚本CentOS 系统上可以使用这套脚本安装 To simplify the installation process during test or development, Docker official provides a convenient installation script, you can install docker on CentOS with the following script:
```bash ```bash
$ curl -fsSL get.docker.com -o get-docker.sh $ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun $ sudo sh get-docker.sh --mirror Aliyun
``` ```
执行这个命令后脚本就会自动的将一切准备工作做好并且把 Docker CE Edge 版本安装在系统中 After execution, the script will have everything prepared, and have installed the stable version on your OS.
### 启动 Docker CE ### Start Docker CE
```bash ```bash
$ sudo systemctl enable docker $ sudo systemctl enable docker
$ sudo systemctl start docker $ sudo systemctl start docker
``` ```
### 建立 docker 用户组 ### Add Docker Usergroups
默认情况下`docker` 命令会使用 [Unix socket](https://en.wikipedia.org/wiki/Unix_domain_socket) 与 Docker 引擎通讯。而只有 `root` 用户和 `docker` 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑一般 Linux 系统上不会直接使用 `root` 用户。因此,更好地做法是将需要使用 `docker` 的用户加入 `docker` 用户组。 Command `docker` uses [Unix socket](https://en.wikipedia.org/wiki/Unix_domain_socket) to communicate with Docker engine by default. Only users of `root` and `docker` groups can communicate with Unix socket of the Docker engine.`root` user is not directly used on Linux systems in general for security. Therefore, it is better to add users who need to use `docker` to the `docker` user group.
建立 `docker` create `docker` group:
```bash ```bash
$ sudo groupadd docker $ sudo groupadd docker
``` ```
将当前用户加入 `docker` add current user to `docker` group:
```bash ```bash
$ sudo usermod -aG docker $USER $ sudo usermod -aG docker $USER
``` ```
退出当前终端并重新登录进行如下测试 Exit current terminal and relogin to test.
### 测试 Docker 是否安装正确 ### Verify the Installation
```bash ```bash
$ docker run hello-world $ docker run hello-world
@@ -141,22 +139,22 @@ For more examples and ideas, visit:
https://docs.docker.com/get-started/ https://docs.docker.com/get-started/
``` ```
若能正常输出以上信息则说明安装成功 If it shows the above message, it means your installation is successful.
### 镜像加速 ### Registry Mirror(In China)
如果在使用过程中发现拉取 Docker 镜像十分缓慢可以配置 Docker [国内镜像加速](mirror.md) If you pull docker images very slowly, then you can configure [Registry Mirror](mirror.md).
### 添加内核参数 ### Add kernel Parameters
如果在 CentOS 使用 Docker CE 看到下面的这些警告信息 If you see the following warnings when using Docker CE,
```bash ```bash
WARNING: bridge-nf-call-iptables is disabled WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled WARNING: bridge-nf-call-ip6tables is disabled
``` ```
请添加内核配置参数以启用这些功能 Please add the kernel parameters to enable these features.
```bash ```bash
$ sudo tee -a /etc/sysctl.conf <<-EOF $ sudo tee -a /etc/sysctl.conf <<-EOF
@@ -165,12 +163,12 @@ net.bridge.bridge-nf-call-iptables = 1
EOF EOF
``` ```
然后重新加载 `sysctl.conf` 即可 Then reload the `sysctl.confg`
```bash ```bash
$ sudo sysctl -p $ sudo sysctl -p
``` ```
### 参考文档 ### References
* [Docker 官方 CentOS 安装文档](https://docs.docker.com/install/linux/docker-ce/centos/) * [Docker Official Installation Documents for Fedora](https://docs.docker.com/install/linux/docker-ce/centos/)

View File

@@ -1,19 +1,18 @@
## Debian 安装 Docker CE ## Install Docker CE on Debian
> WARNING: DO NOT install Docker with apt directly without configuring apt source.
>警告切勿在没有配置 Docker APT 源的情况下直接使用 apt 命令安装 Docker. ### Prerequisites
### 准备工作 #### OS Requirement
#### 系统要求 Docker CE supports the following [Debian](https://www.debian.org/intro/about) versions.
Docker CE 支持以下版本的 [Debian](https://www.debian.org/intro/about) 操作系统:
* Buster 10 * Buster 10
* Stretch 9 * Stretch 9
#### 卸载旧版本 #### Uninstall the Old Versions
旧版本的 Docker 称为 `docker` 或者 `docker-engine`使用以下命令卸载旧版本 The old versions of Docker are called `docker` or `docker-engine`, you can have them uninstalled with the following command:
```bash ```bash
$ sudo apt-get remove docker \ $ sudo apt-get remove docker \
@@ -21,9 +20,9 @@ $ sudo apt-get remove docker \
docker.io docker.io
``` ```
### 使用 APT 安装 ### Install with apt
由于 apt 源使用 HTTPS 以确保软件下载过程中不被篡改因此我们首先需要添加使用 HTTPS 传输的软件包以及 CA 证书 Since the apt source uses HTTPS to make sure that the software is not modified maliciously during download, we have to add the apt source via HTTPS as well as the CA certificate.
```bash ```bash
$ sudo apt-get update $ sudo apt-get update
@@ -37,19 +36,19 @@ $ sudo apt-get install \
software-properties-common software-properties-common
``` ```
鉴于国内网络问题强烈建议使用国内源官方源请在注释中查看 Due to the network issues in China mainland, it is highly recommended for Chinese users to use Chinese sources. Please refer to the official sources in the comments(they are replaced by a Chinese source).
为了确认所下载软件包的合法性需要添加软件源的 GPG 密钥 To verify the validity of the package downloaded, we have to add the GPG key for the package source.
```bash ```bash
$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | sudo apt-key add - $ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | sudo apt-key add -
# 官方源 # Official source
# $ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - # $ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
``` ```
然后我们需要向 `source.list` 中添加 Docker CE 软件源 After that, we need to add the Docker CE source to `source.list`:
```bash ```bash
$ sudo add-apt-repository \ $ sudo add-apt-repository \
@@ -57,18 +56,18 @@ $ sudo add-apt-repository \
$(lsb_release -cs) \ $(lsb_release -cs) \
stable" stable"
# 官方源 # Official source
# $ sudo add-apt-repository \ # $ sudo add-apt-repository \
# "deb [arch=amd64] https://download.docker.com/linux/debian \ # "deb [arch=amd64] https://download.docker.com/linux/debian \
# $(lsb_release -cs) \ # $(lsb_release -cs) \
# stable" # stable"
``` ```
>以上命令会添加稳定版本的 Docker CE APT 如果需要测试或每日构建版本的 Docker CE 请将 stable 改为 test 或者 nightly > The above commands will add the APT source for the stable version of Docker CE. If you need the `test` or `nightly` source, please replace with them to meet your own needs.
#### 安装 Docker CE #### Install Docker CE
更新 apt 软件包缓存并安装 `docker-ce` Update apt cache and install `docker-ce`.
```bash ```bash
$ sudo apt-get update $ sudo apt-get update
@@ -76,43 +75,43 @@ $ sudo apt-get update
$ sudo apt-get install docker-ce $ sudo apt-get install docker-ce
``` ```
### 使用脚本自动安装 ### Install with Automatic Scripts
在测试或开发环境中 Docker 官方为了简化安装流程提供了一套便捷的安装脚本Debian 系统上可以使用这套脚本安装 To simplify the installation process during test or development, Docker official provides a convenient installation script, you can install docker on Debian with the following script:
```bash ```bash
$ curl -fsSL get.docker.com -o get-docker.sh $ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun $ sudo sh get-docker.sh --mirror Aliyun
``` ```
执行这个命令后脚本就会自动的将一切准备工作做好并且把 Docker CE Edge 版本安装在系统中 After execution, the script will have everything prepared, and have installed the stable version on your OS.
### 启动 Docker CE ### Start Docker CE
```bash ```bash
$ sudo systemctl enable docker $ sudo systemctl enable docker
$ sudo systemctl start docker $ sudo systemctl start docker
``` ```
### 建立 docker 用户组 ### Add Docker Usergroups
默认情况下`docker` 命令会使用 [Unix socket](https://en.wikipedia.org/wiki/Unix_domain_socket) 与 Docker 引擎通讯。而只有 `root` 用户和 `docker` 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑一般 Linux 系统上不会直接使用 `root` 用户。因此,更好地做法是将需要使用 `docker` 的用户加入 `docker` 用户组。 Command `docker` uses [Unix socket](https://en.wikipedia.org/wiki/Unix_domain_socket) to communicate with Docker engine by default. Only users of `root` and `docker` groups can communicate with Unix socket of the Docker engine.`root` user is not directly used on Linux systems in general for security. Therefore, it is better to add users who need to use `docker` to the `docker` user group.
建立 `docker` create `docker` group:
```bash ```bash
$ sudo groupadd docker $ sudo groupadd docker
``` ```
将当前用户加入 `docker` add current user to `docker` group:
```bash ```bash
$ sudo usermod -aG docker $USER $ sudo usermod -aG docker $USER
``` ```
退出当前终端并重新登录进行如下测试 Exit current terminal and relogin to test.
### 测试 Docker 是否安装正确 ### Verify the Installation
```bash ```bash
$ docker run hello-world $ docker run hello-world
@@ -145,12 +144,12 @@ For more examples and ideas, visit:
https://docs.docker.com/get-started/ https://docs.docker.com/get-started/
``` ```
若能正常输出以上信息则说明安装成功 If it shows the above message, it means your installation is successful.
### 镜像加速 ### Registry Mirror(In China)
如果在使用过程中发现拉取 Docker 镜像十分缓慢可以配置 Docker [国内镜像加速](mirror.md) If you pull docker images very slowly, then you can configure [Registry Mirror](mirror.md).
### 参考文档 ### References
* [Docker 官方 Debian 安装文档](https://docs.docker.com/install/linux/docker-ce/debian/) * [Docker Official Installation Documents for Debian](https://docs.docker.com/install/linux/docker-ce/debian/)

View File

@@ -1,20 +1,21 @@
## Fedora 安装 Docker CE ## Install Docker CE on Fedora
>警告切勿在没有配置 Docker dnf 源的情况下直接使用 dnf 命令安装 Docker. > WARNING: DO NOT install Docker with dnf directly without configuring dnf source.
### 准备工作 ### Prerequisites
#### 系统要求 #### OS Requirement
Docker CE 支持以下版本的 [Fedora](https://fedoraproject.org/) 操作系统:
Docker CE supports the following [Fedora](https://fedoraproject.org/) versions:
* 28 * 28
* 29 * 29
* 30 * 30
#### 卸载旧版本 #### Uninstall the Old Versions
旧版本的 Docker 称为 `docker` 或者 `docker-engine`使用以下命令卸载旧版本 The old versions of Docker are called `docker` or `docker-engine`, you can have them uninstalled with the following command:
```bash ```bash
$ sudo dnf remove docker \ $ sudo dnf remove docker \
@@ -29,17 +30,16 @@ $ sudo dnf remove docker \
docker-engine docker-engine
``` ```
### 使用 dnf 安装 ### Install with dnf
执行以下命令安装依赖包 Execute the following command to install the dependencies.
```bash ```bash
$ sudo dnf -y install dnf-plugins-core $ sudo dnf -y install dnf-plugins-core
``` ```
Due to the network issues in China mainland, it is highly recommended for Chinese users to use Chinese sources. Please refer to the official sources in the comments(they are replaced by a Chinese source).
鉴于国内网络问题强烈建议使用国内源官方源请在注释中查看 Use the following command to add `dnf` source.
执行下面的命令添加 `dnf` 软件源
```bash ```bash
$ sudo dnf config-manager \ $ sudo dnf config-manager \
@@ -47,40 +47,40 @@ $ sudo dnf config-manager \
https://mirrors.ustc.edu.cn/docker-ce/linux/fedora/docker-ce.repo https://mirrors.ustc.edu.cn/docker-ce/linux/fedora/docker-ce.repo
# 官方源 # Official source
# $ sudo dnf config-manager \ # $ sudo dnf config-manager \
# --add-repo \ # --add-repo \
# https://download.docker.com/linux/fedora/docker-ce.repo # https://download.docker.com/linux/fedora/docker-ce.repo
``` ```
如果需要测试版本的 Docker CE 请使用以下命令 If you want to use the `test` version of Docker CE, use the following command:
```bash ```bash
$ sudo dnf config-manager --set-enabled docker-ce-test $ sudo dnf config-manager --set-enabled docker-ce-test
``` ```
如果需要每日构建版本的 Docker CE 请使用以下命令 As for `nightly` version:
```bash ```bash
$ sudo dnf config-manager --set-enabled docker-ce-nightly $ sudo dnf config-manager --set-enabled docker-ce-nightly
``` ```
你也可以禁用测试版本的 Docker CE You are also free to disable the test version of Docker CE:
```bash ```bash
$ sudo dnf config-manager --set-disabled docker-ce-test $ sudo dnf config-manager --set-disabled docker-ce-test
``` ```
#### 安装 Docker CE #### Install Docker CE
更新 `dnf` 软件源缓存并安装 `docker-ce` Update `dnf` source cacheand then install `docker-ce`.
```bash ```bash
$ sudo dnf update $ sudo dnf update
$ sudo dnf install docker-ce $ sudo dnf install docker-ce
``` ```
你也可以使用以下命令安装指定版本的 Docker You can also use the following command to install a certain docker verion you want:
```bash ```bash
$ dnf list docker-ce --showduplicates | sort -r $ dnf list docker-ce --showduplicates | sort -r
@@ -90,43 +90,43 @@ docker-ce.x86_64 18.06.1.ce-3.fc28 docker-ce-stable
$ sudo dnf -y install docker-ce-18.06.1.ce $ sudo dnf -y install docker-ce-18.06.1.ce
``` ```
### 使用脚本自动安装 ### Install with Automatic Scripts
在测试或开发环境中 Docker 官方为了简化安装流程提供了一套便捷的安装脚本Debian 系统上可以使用这套脚本安装 To simplify the installation process during test or development, Docker official provides a convenient installation script, you can install docker on Fedora with the following script:
```bash ```bash
$ curl -fsSL get.docker.com -o get-docker.sh $ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun $ sudo sh get-docker.sh --mirror Aliyun
``` ```
执行这个命令后脚本就会自动的将一切准备工作做好并且把 Docker CE 最新版本安装在系统中 After execution, the script will have everything prepared, and have installed the stable version on your OS.
### 启动 Docker CE ### Start Docker CE
```bash ```bash
$ sudo systemctl enable docker $ sudo systemctl enable docker
$ sudo systemctl start docker $ sudo systemctl start docker
``` ```
### 建立 docker 用户组 ### Add Docker Usergroups
默认情况下`docker` 命令会使用 [Unix socket](https://en.wikipedia.org/wiki/Unix_domain_socket) 与 Docker 引擎通讯。而只有 `root` 用户和 `docker` 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑一般 Linux 系统上不会直接使用 `root` 用户。因此,更好地做法是将需要使用 `docker` 的用户加入 `docker` 用户组。 Command `docker` uses [Unix socket](https://en.wikipedia.org/wiki/Unix_domain_socket) to communicate with Docker engine by default. Only users of `root` and `docker` groups can communicate with Unix socket of the Docker engine.`root` user is not directly used on Linux systems in general for security. Therefore, it is better to add users who need to use `docker` to the `docker` user group.
建立 `docker` create `docker` group:
```bash ```bash
$ sudo groupadd docker $ sudo groupadd docker
``` ```
将当前用户加入 `docker` add current user to `docker` group:
```bash ```bash
$ sudo usermod -aG docker $USER $ sudo usermod -aG docker $USER
``` ```
退出当前终端并重新登录进行如下测试 Exit current terminal and relogin to test.
### 测试 Docker 是否安装正确 ### Verify the Installation
```bash ```bash
$ docker run hello-world $ docker run hello-world
@@ -159,12 +159,12 @@ For more examples and ideas, visit:
https://docs.docker.com/get-started/ https://docs.docker.com/get-started/
``` ```
若能正常输出以上信息则说明安装成功 If it shows the above message, it means your installation is successful.
### 镜像加速 ### Registry Mirror(In China)
如果在使用过程中发现拉取 Docker 镜像十分缓慢可以配置 Docker [国内镜像加速](mirror.md) If you pull docker images very slowly, then you can configure [Registry Mirror](mirror.md).
### 参考文档 ### References
* [Docker 官方 Fedora 安装文档](https://docs.docker.com/install/linux/docker-ce/fedora) * [Docker Official Installation Documents for Fedora](https://docs.docker.com/install/linux/docker-ce/fedora)

View File

@@ -1,46 +1,46 @@
## macOS 安装 Docker Desktop CE ## Install Docker Desktop CE on maxOS
### 系统要求 ### OS Requirement
[Docker Desktop for Mac](https://docs.docker.com/docker-for-mac/) 要求系统最低为 macOS El Capitan 10.11 The minimum OS version requirement [Docker Desktop for Mac](https://docs.docker.com/docker-for-mac/) is macOS El Capitan 10.11.
### 安装 ### Installation
#### 使用 Homebrew 安装 #### Install with Homebrew
[Homebrew](https://brew.sh/) 的 [Cask](https://caskroom.github.io/) 已经支持 Docker Desktop for Mac因此可以很方便的使用 Homebrew Cask 来进行安装: The [Cask](https://caskroom.github.io/) of [Homebrew](https://brew.sh/) has already supported Docker Desktop for Mac, so we can instrall it with Homebrew Cask easily.
```bash ```bash
$ brew cask install docker $ brew cask install docker
``` ```
#### 手动下载安装 #### Download and Install Manually
如果需要手动下载请点击以下链接下载 [Stable](https://download.docker.com/mac/stable/Docker.dmg) [Edge](https://download.docker.com/mac/edge/Docker.dmg) 版本的 Docker Desktop for Mac。 If you need to download `Docker Desktop for Mac` manually, please click the [Stable](https://download.docker.com/mac/stable/Docker.dmg) or [Edge](https://download.docker.com/mac/edge/Docker.dmg) link to downlaod it.
如同 macOS 其它软件一样安装也非常简单双击下载的 `.dmg` 文件然后将那只叫 [Moby](https://blog.docker.com/2013/10/call-me-moby-dock/) 的鲸鱼图标拖拽到 `Application` 文件夹即可(其间需要输入用户密码)。 Just as other softwares on macOS, the installation of Docker Desktop for macOS is easy. You only need to double click the `.dmg` file, and then drag the whale([Moby](https://blog.docker.com/2013/10/call-me-moby-dock/)) icon to the `Applications` folder. During the process, you will be prompted to enter your password for your mac.
![](_images/install-mac-dmg.png) ![](_images/install-mac-dmg.png)
### 运行 ### Run
从应用中找到 Docker 图标并点击运行 Find the Docker icon from your applications, and double click the icon to run Docker Desktop.
![](_images/install-mac-apps.png) ![](_images/install-mac-apps.png)
运行之后会在右上角菜单栏看到多了一个鲸鱼图标这个图标表明了 Docker 的运行状态 After running, there should be a whale icon on the top right bar of your mac desktop. This icon indicates the running status of Docker.
![](_images/install-mac-menubar.png) ![](_images/install-mac-menubar.png)
第一次点击图标可能会看到这个安装成功的界面点击 "Got it!" 可以关闭这个窗口 For the first time clicking on the icon, you may see the successful installation window. Clicking on "Got it!" will close the window.
![](_images/install-mac-success.png) ![](_images/install-mac-success.png)
以后每次点击鲸鱼图标会弹出操作菜单 Clicking on the whale icon each time afterwards will show you the operation menu.
![](_images/install-mac-menu.png) ![](_images/install-mac-menu.png)
启动终端后通过命令可以检查安装后的 Docker 版本 After opening the terminal, you can check the newly-installed Docker version with commands.
```bash ```bash
$ docker --version $ docker --version
@@ -51,27 +51,28 @@ $ docker-machine --version
docker-machine version 0.16.1, build cce350d7 docker-machine version 0.16.1, build cce350d7
``` ```
如果 `docker version``docker info` 都正常的话可以尝试运行一个 [Nginx 服务器](https://hub.docker.com/_/nginx/) If `docker version` and `docker info` shows no error nor warning, you can try to run an [Nginx Server](https://hub.docker.com/_/nginx/).
```bash ```bash
$ docker run -d -p 80:80 --name webserver nginx $ docker run -d -p 80:80 --name webserver nginx
``` ```
服务运行后可以访问 <http://localhost>,如果看到了 "Welcome to nginx!",就说明 Docker Desktop for Mac 安装成功了。 When the sever is up and running, you can visit <http://localhost>, if you see "Welcome to nginx!", it means the installation of Docker Desktop for macOS is successful.
![](_images/install-mac-example-nginx.png) ![](_images/install-mac-example-nginx.png)
要停止 Nginx 服务器并删除执行下面的命令 To stop the Nginx server and delete it, you can execute the following commands:
```bash ```bash
$ docker stop webserver $ docker stop webserver
$ docker rm webserver $ docker rm webserver
``` ```
### 镜像加速 ### Registry Mirror(In China)
如果在使用过程中发现拉取 Docker 镜像十分缓慢可以配置 Docker [国内镜像加速](mirror.md) If you pull docker images very slowly, then you can configure [Registry Mirror](mirror.md).
### 参考链接 ### References
* [官方文档](https://docs.docker.com/docker-for-mac/install/) * [Official Document](https://docs.docker.com/docker-for-mac/install/)

View File

@@ -1,20 +1,21 @@
## 镜像加速器 ## Mirror Accelerators
国内从 Docker Hub 拉取镜像有时会遇到困难此时可以配置镜像加速器国内很多云服务商都提供了国内加速器服务例如 You may have difficulty pulling images from Docker Hub if you are in China. To resolve this issue, you may configure mirror accelerators. There are many cloud service providers that provide accelerators in China, for example,
* [Azure 中国镜像 `https://dockerhub.azk8s.cn`](https://github.com/Azure/container-service-for-azure-china/blob/master/aks/README.md#22-container-registry-proxy) * [Azure China Mirrors `https://dockerhub.azk8s.cn`](https://github.com/Azure/container-service-for-azure-china/blob/master/aks/README.md#22-container-registry-proxy)
* [阿里云加速器(需登录账号获取)](https://cr.console.aliyun.com/cn-hangzhou/mirrors) * [Alibaba Cloud Accelerator(Login Required)](https://cr.console.aliyun.com/cn-hangzhou/mirrors)
* [七牛云加速器 `https://reg-mirror.qiniu.com`](https://kirk-enterprise.github.io/hub-docs/#/user-guide/mirror) * [Qiniu Cloud Accelerator `https://reg-mirror.qiniu.com`](https://kirk-enterprise.github.io/hub-docs/#/user-guide/mirror)
> 由于镜像服务可能出现宕机建议同时配置多个镜像 > Since some mirror services may be down sometimes, it is recommended to configure multiple mirrors simultaneously.
> 国内各大云服务商均提供了 Docker 镜像加速服务建议根据运行 Docker 的云平台选择对应的镜像加速服务具体请参考官方文档 > Most of the cloud service giants in China provide Docker image acceleration services, you can choose acceleration services based on which platform you are running Docker on. For more detailed information, you may refer to their official documents.
We take Azure China Mirrors `https://dockerhub.azk8s.cn` as an example to introduce more.
我们以 Azure 中国镜像 `https://dockerhub.azk8s.cn` 为例进行介绍
### Ubuntu 16.04+Debian 8+CentOS 7 ### Ubuntu 16.04+Debian 8+CentOS 7
对于使用 [systemd](https://www.freedesktop.org/wiki/Software/systemd/) 的系统,请在 `/etc/docker/daemon.json` 中写入如下内容(如果文件不存在请新建该文件) For Operating Systems using [systemd](https://www.freedesktop.org/wiki/Software/systemd/), please write the following contents inside `/etc/docker/daemon.json`. And if the file does not exist, please create the file.
```json ```json
{ {
@@ -24,41 +25,40 @@
] ]
} }
``` ```
> Note, make sure the file is in valid json format, otherwise Docker will be unable to start.
> 注意一定要保证该文件符合 json 规范否则 Docker 将不能启动 Then restart the service.
之后重新启动服务
```bash ```bash
$ sudo systemctl daemon-reload $ sudo systemctl daemon-reload
$ sudo systemctl restart docker $ sudo systemctl restart docker
``` ```
>注意如果您之前查看旧教程修改了 `docker.service` 文件内容请去掉您添加的内容`--registry-mirror=https://dockerhub.azk8s.cn` > Note: if you refered to the old tutorial previously, and modified the content of `docker.service`, please remove the added contents(`--registry-mirror=https://dockerhub.azk8s.cn`).
### Windows 10 ### Windows 10
对于使用 Windows 10 的系统在系统右下角托盘 Docker 图标内右键菜单选择 `Settings`打开配置窗口后左侧导航菜单选择 `Daemon` `Registry mirrors` 一栏中填写加速器地址 `https://dockerhub.azk8s.cn`之后点击 `Apply` 保存后 Docker 就会重启并应用配置的镜像地址了 For windows 10, choose `Settings` in the list after click on the Docker icon at the right-bottom of the desktop. Then choose `Daemon`, and inside the `Registry mirrors`, fill in `https://dockerhub.azk8s.cn`. And finally click `Apply` to save and apply the changes.
### macOS ### macOS
对于使用 macOS 的用户在任务栏点击 Docker Desktop 应用图标 -> Perferences... -> Daemon -> Registry mirrors在列表中填写加速器地址 `https://dockerhub.azk8s.cn`修改完成之后点击 `Apply & Restart` 按钮Docker 就会重启并应用配置的镜像地址了 For macOS users, click Docker Desktop icon at the task bar -> Perferences... -> Daemon -> Registry mirrors. Then fill in the accelerator address `https://dockerhub.azk8s.cn` in the list. After the modification, click on `Apply & Restart` button, Docker will restart and apply the new mirror address.
### 检查加速器是否生效 ### Verify the Accelerator
执行 `$ docker info`如果从结果中看到了如下内容说明配置成功 After executing `$docker info`, if you can see the following result, you have successfully configured it.
```bash ```bash
Registry Mirrors: Registry Mirrors:
https://dockerhub.azk8s.cn/ https://dockerhub.azk8s.cn/
``` ```
### gcr.io 镜像 ### gcr.io Mirror
国内无法直接获取 `gcr.io/*` 镜像我们可以将 `gcr.io/<repo-name>/<image-name>:<version>` 替换为 `gcr.azk8s.cn/<repo-name>/<image-name>:<version>` ,例如 In China, we cannot fetch `gcr.io/*` mirrors direclty, but we can replace `gcr.io/<repo-name>/<image-name>:<version>` with `gcr.azk8s.cn/<repo-name>/<image-name>:<version>`, for example
```bash ```bash
# $ docker pull gcr.io/google_containers/hyperkube-amd64:v1.9.2 # $ docker pull gcr.io/google_containers/hyperkube-amd64:v1.9.2
$ docker pull gcr.azk8s.cn/google_containers/hyperkube-amd64:v1.9.2 $ docker pull gcr.azk8s.cn/google_containers/hyperkube-amd64:v1.9.2
``` ```

View File

@@ -1,20 +1,21 @@
## 树莓派卡片电脑安装 Docker CE ## Install Docker CE on Raspberry Pi SoC
>警告切勿在没有配置 Docker APT 源的情况下直接使用 apt 命令安装 Docker. > WARNING: DO NOT install Docker with apt directly without configuring apt source.
### 系统要求
Docker CE 不仅支持 `x86_64` 架构的计算机同时也支持 `ARM` 架构的计算机本小节内容以树莓派单片电脑为例讲解 `ARM` 架构安装 Docker CE ### OS Requirement
Docker CE 支持以下版本的 [Raspbian](https://www.raspberrypi.org/downloads/raspbian/) 操作系统: Docker CE supports not only `x86_64` architecture computers, but also `ARM` ones. In this section, we will take Raspberry Pi SoC as an example to explain how to install Docker CE on `ARM` computers.
Docker CE supports the following [Raspbian](https://www.raspberrypi.org/downloads/raspbian/) versions.
* Raspbian Stretch * Raspbian Stretch
** `Raspbian` 是树莓派的开发与维护机构 [树莓派基金会](http://www.raspberrypi.org/) 推荐用于树莓派的首选系统,其基于 `Debian` *NOTE:* `Raspbian` is the top OS on Raspberry Pi recommended by [Raspberry Pi Foundation](https://www.raspberrypi.org/), which is the development and maintenance organization for Raspberry Pi. Raspbian is based on `Debian`.
### 使用 APT 安装 ### Install with apt
由于 apt 源使用 HTTPS 以确保软件下载过程中不被篡改因此我们首先需要添加使用 HTTPS 传输的软件包以及 CA 证书 Since the apt source uses HTTPS to make sure that the software is not modified maliciously during download, we have to add the apt source via HTTPS as well as the CA certificate.
```bash ```bash
$ sudo apt-get update $ sudo apt-get update
@@ -28,19 +29,19 @@ $ sudo apt-get install \
software-properties-common software-properties-common
``` ```
鉴于国内网络问题强烈建议使用国内源官方源请在注释中查看 Due to the network issues in China mainland, it is highly recommended for Chinese users to use Chinese sources. Please refer to the official sources in the comments(they are replaced by a Chinese source).
为了确认所下载软件包的合法性需要添加软件源的 GPG 密钥 To verify the validity of the package downloaded, we have to add the GPG key for the package source.
```bash ```bash
$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/raspbian/gpg | sudo apt-key add - $ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/raspbian/gpg | sudo apt-key add -
# 官方源 # Official source
# $ curl -fsSL https://download.docker.com/linux/raspbian/gpg | sudo apt-key add - # $ curl -fsSL https://download.docker.com/linux/raspbian/gpg | sudo apt-key add -
``` ```
然后我们需要向 `source.list` 中添加 Docker CE 软件源 After that, we need to add the Docker CE source to `source.list`:
```bash ```bash
$ sudo add-apt-repository \ $ sudo add-apt-repository \
@@ -49,18 +50,18 @@ $ sudo add-apt-repository \
stable" stable"
# 官方源 # Official Source
# $ sudo add-apt-repository \ # $ sudo add-apt-repository \
# "deb [arch=armhf] https://download.docker.com/linux/raspbian \ # "deb [arch=armhf] https://download.docker.com/linux/raspbian \
# $(lsb_release -cs) \ # $(lsb_release -cs) \
# stable" # stable"
``` ```
>以上命令会添加稳定版本的 Docker CE APT 如果需要测试或每日构建版本的 Docker CE 请将 stable 改为 test 或者 nightly > The above commands will add the APT source for the stable version of Docker CE. If you need the `test` or `nightly` source, please replace with them to meet your own needs.
#### 安装 Docker CE #### Install Docker CE
更新 apt 软件包缓存并安装 `docker-ce` Update apt cache and install `docker-ce`.
```bash ```bash
$ sudo apt-get update $ sudo apt-get update
@@ -68,43 +69,43 @@ $ sudo apt-get update
$ sudo apt-get install docker-ce $ sudo apt-get install docker-ce
``` ```
### 使用脚本自动安装 ### Install with Automatic Scripts
在测试或开发环境中 Docker 官方为了简化安装流程提供了一套便捷的安装脚本Raspbian 系统上可以使用这套脚本安装 To simplify the installation process during test or development, Docker official provides a convenient installation script, you can install docker on Raspbian with the following script:
```bash ```bash
$ curl -fsSL get.docker.com -o get-docker.sh $ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun $ sudo sh get-docker.sh --mirror Aliyun
``` ```
执行这个命令后脚本就会自动的将一切准备工作做好并且把 Docker CE Edge 版本安装在系统中 After execution, the script will have everything prepared, and have installed the stable version on your OS.
### 启动 Docker CE ### Start Docker CE
```bash ```bash
$ sudo systemctl enable docker $ sudo systemctl enable docker
$ sudo systemctl start docker $ sudo systemctl start docker
``` ```
### 建立 docker 用户组 ### Add Docker Usergroups
默认情况下`docker` 命令会使用 [Unix socket](https://en.wikipedia.org/wiki/Unix_domain_socket) 与 Docker 引擎通讯。而只有 `root` 用户和 `docker` 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑一般 Linux 系统上不会直接使用 `root` 用户。因此,更好地做法是将需要使用 `docker` 的用户加入 `docker` 用户组。 Command `docker` uses [Unix socket](https://en.wikipedia.org/wiki/Unix_domain_socket) to communicate with Docker engine by default. Only users of `root` and `docker` groups can communicate with Unix socket of the Docker engine.`root` user is not directly used on Linux systems in general for security. Therefore, it is better to add users who need to use `docker` to the `docker` user group.
建立 `docker` create `docker` group:
```bash ```bash
$ sudo groupadd docker $ sudo groupadd docker
``` ```
将当前用户加入 `docker` add current user to `docker` group:
```bash ```bash
$ sudo usermod -aG docker $USER $ sudo usermod -aG docker $USER
``` ```
退出当前终端并重新登录进行如下测试 Exit current terminal and relogin to test.
### 测试 Docker 是否安装正确 ### Verify the Installation
```bash ```bash
$ docker run arm32v7/hello-world $ docker run arm32v7/hello-world
@@ -137,10 +138,10 @@ For more examples and ideas, visit:
https://docs.docker.com/get-started/ https://docs.docker.com/get-started/
``` ```
若能正常输出以上信息则说明安装成功 If it shows the above message, it means your installation is successful.
*注意* ARM 平台不能使用 `x86` 镜像查看 Raspbian 可使用镜像请访问 [arm32v7](https://hub.docker.com/u/arm32v7/) *NOTE:* ARM platform cannot use `x86` mirrors, to view a list of the mirrors supported on Raspbian, please visit [arm32v7](https://hub.docker.com/u/arm32v7/).
### 镜像加速 ### Registry Mirror(In China)
如果在使用过程中发现拉取 Docker 镜像十分缓慢可以配置 Docker [国内镜像加速](mirror.md) If you pull docker images very slowly, then you can configure [Registry Mirror](mirror.md).

View File

@@ -1,23 +1,23 @@
## Ubuntu 安装 Docker CE ## Install Docker CE on Ubuntu
>警告切勿在没有配置 Docker APT 源的情况下直接使用 apt 命令安装 Docker. > WARNING: DO NOT install Docker CE directly using apt without configuring Docker APT source.
### 准备工作 ### Prerequisites
#### 系统要求 #### System requirements
Docker CE 支持以下版本的 [Ubuntu](https://www.ubuntu.com/server) 操作系统: Docker CE supported [Ubuntu](https://www.ubuntu.com/server) versions:
* Disco 19.04 * Disco 19.04
* Cosmic 18.10 * Cosmic 18.10
* Bionic 18.04 (LTS) * Bionic 18.04 (LTS)
* Xenial 16.04 (LTS) * Xenial 16.04 (LTS)
Docker CE 可以安装在 64 位的 x86 平台或 ARM 平台上Ubuntu 发行版中LTSLong-Term-Support长期支持版本会获得 5 年的升级维护支持这样的版本会更稳定因此在生产环境中推荐使用 LTS 版本 Docker CE can be installed on x86 platform or ARM. In Ubuntu distributions, LTS (Long-Term-Support) will get 5 years updating support, distributions like this will be stable. Therefore, LTS version is recommended in production environment.
#### 卸载旧版本 #### Uninstall old version
旧版本的 Docker 称为 `docker` 或者 `docker-engine`使用以下命令卸载旧版本 Old version of Docker is called `docker` or `docker-engine`. Use the following command to uninstall the old version:
```bash ```bash
$ sudo apt-get remove docker \ $ sudo apt-get remove docker \
@@ -25,9 +25,9 @@ $ sudo apt-get remove docker \
docker.io docker.io
``` ```
### 使用 APT 安装 ### Use APT to install
由于 `apt` 源使用 HTTPS 以确保软件下载过程中不被篡改因此我们首先需要添加使用 HTTPS 传输的软件包以及 CA 证书 Because the `apt` source uses HTTPS to ensure that software downloads are not tampered with. Therefore, we need to add software packages and CA certificates that are transmitted using HTTPS first.
```bash ```bash
$ sudo apt-get update $ sudo apt-get update
@@ -39,19 +39,19 @@ $ sudo apt-get install \
software-properties-common software-properties-common
``` ```
鉴于国内网络问题强烈建议使用国内源官方源请在注释中查看 If you are in China, it is strongly recommended to use Chinese sources. The official sources are in the comments.
为了确认所下载软件包的合法性需要添加软件源的 `GPG` 密钥 In order to confirm the validity of the downloaded package, we need to add the `GPG` key of the software source.
```bash ```bash
$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - $ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# 官方源 # official
# $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - # $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
``` ```
然后我们需要向 `source.list` 中添加 Docker 软件源 Then, we need to add Docker software source to `source.list`
```bash ```bash
$ sudo add-apt-repository \ $ sudo add-apt-repository \
@@ -60,18 +60,18 @@ $ sudo add-apt-repository \
stable" stable"
# 官方源 # official
# $ sudo add-apt-repository \ # $ sudo add-apt-repository \
# "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ # "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
# $(lsb_release -cs) \ # $(lsb_release -cs) \
# stable" # stable"
``` ```
>以上命令会添加稳定版本的 Docker CE APT 镜像源如果需要测试或每日构建版本的 Docker CE 请将 stable 改为 test 或者 nightly > The above commands will add stable Docker CE APT source. If you need the `test` or `nightly` version of Docker, you can change `stable` to `test` or `nightly`.
#### 安装 Docker CE #### Install Docker CE
更新 apt 软件包缓存并安装 `docker-ce` Update apt cache and install `docker-ce`:
```bash ```bash
$ sudo apt-get update $ sudo apt-get update
@@ -79,43 +79,43 @@ $ sudo apt-get update
$ sudo apt-get install docker-ce $ sudo apt-get install docker-ce
``` ```
### 使用脚本自动安装 ### Auto install by script
在测试或开发环境中 Docker 官方为了简化安装流程提供了一套便捷的安装脚本Ubuntu 系统上可以使用这套脚本安装 Docker Offical has provided a set of convenient installation scripts which can be installed on Ubuntu for test or dev environments.
```bash ```bash
$ curl -fsSL get.docker.com -o get-docker.sh $ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun $ sudo sh get-docker.sh --mirror Aliyun
``` ```
执行这个命令后脚本就会自动的将一切准备工作做好并且把 Docker CE Edge 版本安装在系统中 The script will have everything prepared and have installed the stable version of Docker CE for the system after execution.
### 启动 Docker CE ### Launcher Docker CE
```bash ```bash
$ sudo systemctl enable docker $ sudo systemctl enable docker
$ sudo systemctl start docker $ sudo systemctl start docker
``` ```
### 建立 docker 用户组 ### Add Docker Usergroups
默认情况下`docker` 命令会使用 [Unix socket](https://en.wikipedia.org/wiki/Unix_domain_socket) 与 Docker 引擎通讯。而只有 `root` 用户和 `docker` 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑一般 Linux 系统上不会直接使用 `root` 用户。因此,更好地做法是将需要使用 `docker` 的用户加入 `docker` 用户组。 Command `docker` uses [Unix socket](https://en.wikipedia.org/wiki/Unix_domain_socket) to communicate with Docker engine by default. Only users of `root` and `docker` groups can communicate with Unix socket of the Docker engine.`root` user is not directly used on Linux systems in general for security. Therefore, it is better to add users who need to use `docker` to the `docker` user group.
建立 `docker` create `docker` group:
```bash ```bash
$ sudo groupadd docker $ sudo groupadd docker
``` ```
将当前用户加入 `docker` add current user to `docker` group:
```bash ```bash
$ sudo usermod -aG docker $USER $ sudo usermod -aG docker $USER
``` ```
退出当前终端并重新登录进行如下测试 Exit current terminal and relogin to test.
### 测试 Docker 是否安装正确 ### Verify the Installation
```bash ```bash
$ docker run hello-world $ docker run hello-world
@@ -148,12 +148,12 @@ For more examples and ideas, visit:
https://docs.docker.com/get-started/ https://docs.docker.com/get-started/
``` ```
若能正常输出以上信息则说明安装成功 If it shows above the message, it means your installation is successful.
### 镜像加速 ### Registry Mirror(In China)
如果在使用过程中发现拉取 Docker 镜像十分缓慢可以配置 Docker [国内镜像加速](mirror.md) If you pull docker images very slowly, then you can configure [Registry Mirror](mirror.md).
### 参考文档 ### References
* [Docker 官方 Ubuntu 安装文档](https://docs.docker.com/install/linux/docker-ce/ubuntu/) * [Docker Official Installation Documents for Ubuntu](https://docs.docker.com/install/linux/docker-ce/ubuntu/)

View File

@@ -1,33 +1,31 @@
## Windows 10 PC 安装 Docker Desktop CE ## Install Docker Desktop CE on Windows 10
### 系统要求 ### System requirements
[Docker Desktop for Windows](https://docs.docker.com/docker-for-windows/install/) 支持 64 位版本的 Windows 10 Pro,且必须开启 Hyper-V。 [Docker Desktop for Windows](https://docs.docker.com/docker-for-windows/install/) requires Windows 10 Pro 64-bit that activates [Hyper-V](https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/about/).
### 安装 ### Install
点击以下链接下载 [Stable](https://download.docker.com/win/stable/Docker%20Desktop%20Installer.exe) [Edge](https://download.docker.com/win/edge/Docker%20Desktop%20Installer.exe) 版本的 Docker Desktop for Windows。 Download Docker Desktop for Windows [Stable](https://download.docker.com/win/stable/Docker%20Desktop%20Installer.exe) or [Edge](https://download.docker.com/win/edge/Docker%20Desktop%20Installer.exe), then double-click `Docker Desktop Installer.exe` to install.
下载好之后双击 `Docker Desktop Installer.exe` 开始安装 ### Running
### 运行 Search Docker in Windows and click `Docker for Windows` to run.
Windows 搜索栏输入 Docker 点击 Docker for Windows 开始运行
![](_images/install-win-docker-app-search.png) ![](_images/install-win-docker-app-search.png)
Docker CE 启动之后会在 Windows 任务栏出现鲸鱼图标 There is a whale icon in the Windows taskbar after running Docker CE.
![](_images/install-win-taskbar-circle.png) ![](_images/install-win-taskbar-circle.png)
等待片刻点击 Got it 开始使用 Docker CE Wait a moment and click "Got it" to start using Docker CE.
![](_images/install-win-success-popup-cloud.png) ![](_images/install-win-success-popup-cloud.png)
### 镜像加速 ### Registry Mirror(In China)
如果在使用过程中发现拉取 Docker 镜像十分缓慢可以配置 Docker [国内镜像加速](mirror.md) If you pull docker images very slowly, then you can configure [Registry Mirror](mirror.md).
### 参考链接 ### Links
* [官方文档](https://docs.docker.com/docker-for-windows/install/) * [Docker Offical Docs](https://docs.docker.com/docker-for-windows/install/)

View File

@@ -1,8 +1,8 @@
# 简介 # Introduction
本章将带领你进入 Docker 的世界 This chapter will show you the docker's world.
什么是 Docker What is Docker?
用它会带来什么样的好处 What benefits will it bring?
好吧让我们带着问题开始这神奇之旅 OK, let's start with questions.

View File

@@ -1,22 +1,22 @@
## 什么是 Docker ## What is Docker
Docker 最初是 dotCloud 公司创始人 Solomon Hykes 在法国期间发起的一个公司内部项目它是基于 dotCloud 公司多年云服务技术的一次革新并于 [2013 3 月以 Apache 2.0 授权协议开源][docker-soft]主要项目代码在 [GitHub](https://github.com/moby/moby) 上进行维护。Docker 项目后来还加入了 Linux 基金会,并成立推动 [开放容器联盟(OCI](https://www.opencontainers.org/) Docker is an in-company project launched by Solomon Hykes who is the founder of dotCloud when he was in France, it's a revolution based on dotCloud's years of cloud service experience, and [open-sourced with Apache 2.0 in 2013.03][docker-soft] maintained in [GitHub](https://github.com/moby/moby). Then, Docker joined the Linux Foundation and promoted [Open Containers Initlative (OCI)](https://www.opencontainers.org/).
Docker 自开源后受到广泛的关注和讨论至今其 [GitHub 项目](https://github.com/moby/moby) 已经超过 5 万 2 千个星标和一万多个 fork。甚至由于 Docker 项目的火爆,在 2013 年底,[dotCloud 公司决定改名为 Docker](https://blog.docker.com/2013/10/dotcloud-is-becoming-docker-inc/)。Docker 最初是在 Ubuntu 12.04 上开发实现的Red Hat 则从 RHEL 6.5 开始对 Docker 进行支持Google 也在其 PaaS 产品中广泛应用 Docker。 Docker has aroused widespread concerns and discussions and had 52K stars and 10K forks in its [GitHub page](https://github.com/moby/moby) since being open-sourced. At the end of 2013, [dotCloud even decided to rename it to Docker](https://blog.docker.com/2013/10/dotcloud-is-becoming-docker-inc/) due to the popularity of the project. Docker was developed in Ubuntu 12.04 at the beginning. Red Hat has supported Dokcer since RHEL 6.5. Google has also widely applied Docker in its PaaS products.
Docker 使用 Google 公司推出的 [Go 语言](https://golang.org/) 进行开发实现,基于 Linux 内核的 [cgroup](https://zh.wikipedia.org/wiki/Cgroups)[namespace](https://en.wikipedia.org/wiki/Linux_namespaces),以及 [AUFS](https://en.wikipedia.org/wiki/Aufs) 类的 [Union FS](https://en.wikipedia.org/wiki/Union_mount) 等技术,对进程进行封装隔离,属于 [操作系统层面的虚拟化技术](https://en.wikipedia.org/wiki/Operating-system-level_virtualization)。由于隔离的进程独立于宿主和其它的隔离的进程,因此也称其为容器。最初实现是基于 [LXC](https://linuxcontainers.org/lxc/introduction/),从 0.7 版本以后开始去除 LXC转而使用自行开发的 [libcontainer](https://github.com/docker/libcontainer),从 1.11 开始,则进一步演进为使用 [runC](https://github.com/opencontainers/runc) [containerd](https://github.com/containerd/containerd) Docker is developed with [GO](https://golang.org/) launched by Google, based on [cgroup](https://zh.wikipedia.org/wiki/Cgroups) and [namespace](https://en.wikipedia.org/wiki/Linux_namespaces) of Linux Kernel and [Union FS](https://en.wikipedia.org/wiki/Union_mount) like [AUFS](https://en.wikipedia.org/wiki/Aufs) to package and isolate the processes which belong to [Operating system level virtualization technology](https://en.wikipedia.org/wiki/Operating-system-level_virtualization). It is also called container because of the fact that the isolated processes are independent of the host and other isolated processes. The initial implementation is based on [LXC](https://linuxcontainers.org/lxc/introduction/). It removed LXC and use [libcontainer](https://github.com/docker/libcontainer) instead which is developed by themself since 0.7. Starting with 1.11, it uses [runC](https://github.com/opencontainers/runc) and [containerd](https://github.com/containerd/containerd) further.
![Docker 架构](https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/media/docker-on-linux.png) ![Docker Architecture](https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/media/docker-on-linux.png)
> `runc` 是一个 Linux 命令行工具用于根据 [OCI容器运行时规范](https://github.com/opencontainers/runtime-spec) 创建和运行容器。 > `runc` is a Linux command-line tool for creating and running containers according to the [OCI container runtime specification](https://github.com/opencontainers/runtime-spec).
> `containerd` 是一个守护程序它管理容器生命周期提供了在一个节点上执行容器和管理镜像的最小功能集 > `containerd` is a daemon that manages container life cycle from downloading and unpacking the container image to container execution and supervision.
Docker 在容器的基础上进行了进一步的封装从文件系统网络互联到进程隔离等等极大的简化了容器的创建和维护使得 Docker 技术比虚拟机技术更为轻便快捷 Docker is further packaged on a container basis, from file system, network interconnection to process isolation, etc, greatly simplifying container craetion and maintenance.
下面的图片比较了 Docker 和传统虚拟化方式的不同之处传统虚拟机技术是虚拟出一套硬件后在其上运行一个完整操作系统在该系统上再运行所需应用进程而容器内的应用进程直接运行于宿主的内核容器内没有自己的内核而且也没有进行硬件虚拟因此容器要比传统虚拟机更为轻便 The images below compare the differences between Docker and Traditional Virtualization. The traditional Virtual Machine technology is to virtualize a set of hardwares to run a complete operation system and run the required application process on this system. The application process in the container runs directly on the host kernel, and the container does not have its own Kernel and hardware virtualiztion. Therefore, containers are lighter than traditional virtual machines.
![传统虚拟化](_images/virtualization.png) ![Traditional Virtualization](_images/virtualization.png)
![Docker](_images/docker.png) ![Docker](_images/docker.png)

View File

@@ -1,40 +1,41 @@
## 为什么要使用 Docker ## Why use Docker ?
As a new virtualization technology, Docker has many advantages over
other traditional virtualization solutions.
作为一种新兴的虚拟化方式Docker 跟传统的虚拟化方式相比具有众多的优势 ### Use System Resources more Efficiently
### 更高效的利用系统资源 Docker has high utilization rate of system resources, because container does not need additional overhead such as hardware virtualization or running the whole system. It's more efficient than traditional virtual machine technology in terms of execution speed, memory expense and file storage speed. Therefore, a host with the same configuration can often run more applications than virtual machine technology.
由于容器不需要进行硬件虚拟以及运行完整操作系统等额外开销Docker 对系统资源的利用率更高无论是应用执行速度内存损耗或者文件存储速度都要比传统虚拟机技术更高效因此相比虚拟机技术一个相同配置的主机往往可以运行更多数量的应用 ### Faster Startup Time
### 更快速的启动时间 The traditional virtual machine technology needs minutes to startup application service, but Docker can do it in seconds or milliseconds due to running on the kernel of host machine and not running the whole system. It saves a considerable amount of time for development, testing and deployment.
传统的虚拟机技术启动应用服务往往需要数分钟 Docker 容器应用由于直接运行于宿主内核无需启动完整的操作系统因此可以做到秒级甚至毫秒级的启动时间大大的节约了开发测试部署的时间 ### Consistent Operating Environment
### 一致的运行环境 Environment setup consistency is a common problem in DevOps. Inconsistent configuration can cause some bugs not found at development time but revealed at production due to the subtle differences between the development, testing and production environments. The docker image can provide a complete runtime environment without kernel, which ensures consistency of the application environment throughout its lifecycle, eliminating issues like * This piece of code is okey on my machine *.
开发过程中一个常见的问题是环境一致性问题由于开发环境测试环境生产环境不一致导致有些 bug 并未在开发过程中被发现 Docker 的镜像提供了除内核外完整的运行时环境确保了应用运行环境一致性从而不会再出现 *这段代码在我机器上没问题啊* 这类问题
### 持续交付和部署 ### CI/CD
对开发和运维[DevOps](https://zh.wikipedia.org/wiki/DevOps)人员来说,最希望的就是一次创建或配置,可以在任意地方正常运行。 For development and operation[DevOps](https://zh.wikipedia.org/wiki/DevOps)engineers, the desirable thing is to create and configure once to run anywhere.
使用 Docker 可以通过定制应用镜像来实现持续集成持续交付部署开发人员可以通过 [Dockerfile](../image/dockerfile/) 来进行镜像构建并结合 [持续集成(Continuous Integration)](https://en.wikipedia.org/wiki/Continuous_integration) 系统进行集成测试,而运维人员则可以直接在生产环境中快速部署该镜像,甚至结合 [持续部署(Continuous Delivery/Deployment)](https://en.wikipedia.org/wiki/Continuous_delivery) 系统进行自动部署。 CI/CD can be achieved by customizing application mirrors with Docker. Developers can build images with [Dockerfile](../image/dockerfile/) and use [Continuous Integration](https://en.wikipedia.org/wiki/Continuous_integration) for integration testing. Operation teams can deploy production environments quickly with the images, and even make automatic deployments possible by using [Continuous Delivery/Deployment](https://en.wikipedia.org/wiki/Continuous_delivery) techniques.
而且使用 `Dockerfile` 使镜像构建透明化不仅仅开发团队可以理解应用运行环境也方便运维团队理解应用运行所需条件帮助更好的生产环境中部署该镜像 And `Dockerfile` makes mirror construction transparent. Not only does the development team understand the application runtime environment, but it also facilitates the operation team to understand the requirements of the application and better deployment in production environments.
### 更轻松的迁移 ### Easier migration
由于 Docker 确保了执行环境的一致性使得应用的迁移更加容易Docker 可以在很多平台上运行无论是物理机虚拟机公有云私有云甚至是笔记本其运行结果是一致的因此用户可以很轻易的将在一个平台上运行的应用迁移到另一个平台上而不用担心运行环境的变化导致应用无法正常运行的情况 Because Docker ensures consistency in the execution environment, application migration is easier. Docker can run on multiple platforms, including physical, virtual machines or public/private clouds, with consistent results. Therefore, users can easily migrate applications from one platform to another whitout worrying about the cross-platform difficulties.
### 更轻松的维护和扩展 ### Easier maintenance and extension
Docker 使用的分层存储以及镜像的技术使得应用重复部分的复用更为容易也使得应用的维护更新更加简单基于基础镜像进一步扩展镜像也变得非常简单此外Docker 团队同各个开源项目团队一起维护了一大批高质量的 [官方镜像](https://hub.docker.com/search/?type=image&image_filter=official),既可以直接在生产环境使用,又可以作为基础进一步定制,大大的降低了应用服务的镜像制作成本。 Docker uses layered storage and mirror technology, so it is easier to reuse the repetitive parts of the application and simpler to expand the image based on the basic mirror. In addition, the Docker team maintains a lot of high-quality [official images](https://hub.docker.com/search/?type=image&image_filter=official) together with various open-source project teams. It can be used directly in the production environment with customization, greatly reducing the cost of image production of various application services.
### 对比传统虚拟机总结 ### Contrast traditional virtual machines
| 特性 | 容器 | 虚拟机 | | Feature | Container | Virtual Machine |
| :-------- | :-------- | :---------- | | :-------- | :-------- | :---------- |
| 启动 | 秒级 | 分钟级 | | Boot | seconds | minutes |
| 硬盘使用 | 一般为 `MB` | 一般为 `GB` | | Disk Usage | MB | GB |
| 性能 | 接近原生 | 弱于 | | Performance | close to native | weaker |
| 系统支持量 | 单机支持上千个容器 | 一般几十个 | | System Support | thousands | dozens in general |