246 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
48718d6035 Fixed error
Signed-off-by: Kang Huaishuai <khs1994@khs1994.com>
2019-09-01 15:15:53 +08:00
khs1994
8666d2683f Update Docker Desktop name
Signed-off-by: khs1994 <khs1994@khs1994.com>
2019-09-01 15:03:32 +08:00
khs1994
84c2183cc8 [Machine] Update to v0.16.1
Signed-off-by: khs1994 <khs1994@khs1994.com>
2019-09-01 14:50:40 +08:00
khs1994
7ec38273bb [Compose] Update to v1.24.1
Signed-off-by: khs1994 <khs1994@khs1994.com>
2019-09-01 14:46:33 +08:00
khs1994
6bca9e8dff Update CoreOS: remove outdated quickstart 2019-09-01 14:16:10 +08:00
khs1994
6c6d2ac973 [etcd] Update to v3.4.x 2019-08-31 22:57:43 +08:00
khs1994
8747860b95 compose wordpress update mysql to v8.0.x #415 2019-08-31 22:11:34 +08:00
khs1994
5a00a6b32f Update CI
* Update drone to v1.x
* Add GitHub Actions
2019-08-31 21:15:51 +08:00
khs1994
8a3be4634e Update install 2019-08-31 18:35:14 +08:00
khs1994
c075122492 Update project docker image name #416 2019-08-31 17:47:38 +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
Kang Huaishuai
593a0c39ff Merge pull request #413 from baijunyao/master
Use aliyun compose mirrors
2019-08-14 22:06:45 +08:00
baijunyao
823239010a Use aliyun compose mirrors 2019-08-14 21:50:30 +08:00
Kerwin.Sun
d00b6e1911 trans introduction--why 2019-08-11 18:49:23 +08:00
Kang HuaiShuai
b8dc1a7b16 Add image
Signed-off-by: Kang HuaiShuai <khs1994@khs1994.com>
2019-07-03 12:22:22 +08:00
Kang HuaiShuai
710c1ec457 Fix dead link
Signed-off-by: Kang HuaiShuai <khs1994@khs1994.com>
2019-07-03 12:06:31 +08:00
Kang HuaiShuai
b9247c16df Update compose django, Fixed #405
Signed-off-by: Kang HuaiShuai <khs1994@khs1994.com>
2019-07-03 11:49:11 +08:00
khs1994
59af28af86 Merge pull request #407 from yongchengzhao/master
- Fix issue #406: Describe more correctly.
2019-06-28 11:20:06 +08:00
khs1994
0baf0fec99 Merge pull request #409 from yongchengzhao/master
- Fix issue #408: Fix typos.
2019-06-28 11:17:28 +08:00
yongchengzhao
d14a0e0c4a - Fix issue #408: Fix typos. 2019-06-28 10:16:12 +08:00
yongchengzhao
e7c1782c51 - Fix issue #408: Fix typos. 2019-06-28 10:04:57 +08:00
yongchengzhao
7b02f90f09 - Fix issue #406: Describe more correctly. 2019-06-27 17:03:03 +08:00
khs1994
4ed6156a03 Add ci icon [skip ci] 2019-05-14 00:29:12 +08:00
khs1994
3b959abf68 Update SUMMARY 2019-05-14 00:17:11 +08:00
khs1994
a0c7670738 Update README [skip ci] 2019-05-13 23:43:29 +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
khs1994
00ec580e74 Fix gitbook build error: use page-treeview@2.9.8 2019-05-13 22:58:26 +08:00
00kai0
3974a2de24 trans introduction's README.md and what.md 2019-05-13 15:34:13 +08:00
khs1994
3442dab121 Update cloud 2019-05-12 10:14:00 +08:00
khs1994
2e747fe2a5 [install] Update mirror: remove docker cn registry #370 2019-05-12 09:44:17 +08:00
khs1994
df2537b721 Update cloud 2019-05-12 09:41:35 +08:00
khs1994
bf04ac99a3 Update jd link [skip ci] 2019-05-10 07:27:55 +08:00
khs1994
77c8ae525a Buy book by wechat miniprogram [skip ci] 2019-05-07 23:16:36 +08:00
Baohua Yang
f7dcffc7be Merge branch 'master' of github.com:yeasy/docker_practice 2019-05-05 19:31:08 +08:00
Baohua Yang
a17f3f6b2f Add resource 2019-05-05 19:31:06 +08:00
khs1994
8576e16b61 ubuntu 14.04,debian 7 and 8 EOL 2019-04-29 09:29:46 +08:00
khs1994
4949de94c4 Merge pull request #399 from SmallTianTian/patch-1
expose port.
2019-04-15 20:22:09 +08:00
SmallTianTian
44e504c604 expose port. 2019-04-15 11:11:58 +08:00
khs1994
0370871867 Add BuildKit and docker manifest command. close #390 ,close #391
Signed-off-by: khs1994 <khs1994@khs1994.com>
2019-03-29 12:02:18 +08:00
khs1994
d3c197ddfc show repo language is go 2019-03-22 10:35:29 +08:00
khs1994
8fc2003414 Update README
* use jd.com cps url, analysis docker user trend
2019-03-09 11:16:27 +08:00
khs1994
c446640591 Fix format and update outdate content 2019-03-08 12:21:07 +08:00
Baohua Yang
6a97772e79 Merge pull request #388 from daixiang0/delete-blank
Remove unused blank spaces
2019-02-22 23:44:13 +08:00
Xiang Dai
d4bbcc0cfb delete all duplicate empty blanks
Signed-off-by: Xiang Dai <764524258@qq.com>
2019-02-21 10:53:33 +08:00
khs1994
994f6ac101 Replace http with https 2019-01-06 10:15:13 +08:00
khs1994
fbf5a286ab Update install 2019-01-06 10:00:38 +08:00
khs1994
81e68f241c Update docker official docs link 2019-01-06 09:50:03 +08:00
khs1994
aff886341f Update link 2019-01-06 09:40:31 +08:00
khs1994
44530ff366 Add aliyun mirror 2019-01-01 17:59:58 +08:00
khs1994
e2baa6401a replace crlf,Fix #338 2019-01-01 10:30:49 +08:00
khs1994
560c23797a Update typeset 2018-12-31 16:09:34 +08:00
khs1994
efee23eca7 Add cases/ci travis
Signed-off-by: khs1994 <khs1994@khs1994.com>
2018-12-31 15:57:44 +08:00
khs1994
234ac706a3 Update dockerfile format 2018-12-31 14:50:31 +08:00
khs1994
11e2bf1701 Add Dockerfile multi stage laravel 2018-12-31 14:39:26 +08:00
khs1994
c8b73b20c6 Add php image 2018-12-31 09:25:33 +08:00
khs1994
2921a406d6 Update kubernetes 2018-12-31 09:06:28 +08:00
khs1994
944cb0dfd1 Update fedora.md 2018-12-30 17:43:34 +08:00
khs1994
2437dd0158 Fix last commit error 2018-12-26 16:47:44 +08:00
Baohua Yang
a7660df66e Add more debug skills 2018-12-26 10:11:42 +08:00
Baohua Yang
e2d5a2dff0 Add debug skills 2018-12-26 10:05:42 +08:00
khs1994
9899c7028e Fix image link 404 2018-12-25 19:20:32 +08:00
khs1994
e1552503ac Merge pull request #385 from jxlwqq/patch-1
Fix CentOS website
2018-12-22 00:08:19 +08:00
jxlwqq
35f4ca76b6 Fix CentOS website 2018-12-22 00:04:50 +08:00
khs1994
e828a4888d Update debian to stretch 2018-12-19 17:27:21 +08:00
khs1994
af7663bd61 Update ubuntu to 18.04 2018-12-19 17:24:52 +08:00
khs1994
4d38aaad3b Fix #383, base image not include wget,Update based image to debian:stretch 2018-12-19 17:08:32 +08:00
xufanglu
89f7f3cf98 Use daemon.json 2018-12-18 13:13:52 +08:00
khs1994
7a45ac029e Update soft version 2018-12-15 23:04:32 +08:00
khs1994
6d4702484d replace docker cloud with docker hub 2018-12-14 19:36:17 +08:00
khs1994
a50641d973 replace docker store with docker hub 2018-12-14 19:08:14 +08:00
khs1994
3b798d1e64 Update format 2018-12-13 20:51:30 +08:00
khs1994
553ca77a07 Merge pull request #380 from daixiang0/update-faq
Update stop cmd
2018-12-13 19:24:00 +08:00
daixiang0
e3c46e3b09 Update stop cmd
`docker stop` send SIGTERM, and then SIGKILL after grace period,
while `docker kill` send SIGTERM directly,
so `docker stop` is more safe and ensure the integrity of the data.

Signed-off-by: daixiang0 <764524258@qq.com>
2018-12-13 19:21:11 +08:00
long
86657b8742 Update data root info 2018-12-13 18:57:41 +08:00
long
39b69945cc Update docker save command info
Signed-off-by: daixiang0 <764524258@qq.com>
2018-12-13 18:13:08 +08:00
khs1994
15ce0d8e04 Update storage drivers #378 #375 2018-12-13 18:01:45 +08:00
khs1994
8bd26974b7 Merge pull request #374 from mapleeit/patch-1
fix: fix typos
2018-12-11 14:41:27 +08:00
Maple Miao
38097d47eb fix: fix typos 2018-12-11 14:30:59 +08:00
Devin-Li
cb5813d10a update entrypotin.md 2018-12-10 18:20:10 +08:00
khs1994
2cc1207dc3 Update ubuntu version to 18.04
Signed-off-by: khs1994 <khs1994@khs1994.com>
2018-12-08 21:48:16 +08:00
Baohua Yang
6f12336f33 Merge pull request #371 from yeasy/miniprogram
Add wechat mini-program info
2018-12-08 21:12:30 +08:00
khs1994
49841871aa Add miniprogram 2018-12-08 18:08:27 +08:00
khs1994
1b306447ef Update Dockerfile
Signed-off-by: khs1994 <khs1994@khs1994.com>
2018-11-02 08:26:50 +08:00
khs1994
dfa885f4f0 Update supported os
Signed-off-by: khs1994 <khs1994@khs1994.com>
2018-11-02 08:01:29 +08:00
Baohua Yang
08dc228718 Fix issue#362: update book info 2018-10-23 21:35:18 +08:00
khs1994
cabdcdb898 Merge pull request #364 from wxy325/master
Update django.md, Fix a typo
2018-10-23 12:51:54 +08:00
Xiangyu Wu
627b17d2f5 Update django.md
Fix typo
2018-10-22 15:25:40 -07:00
khs1994
33bccf2ac4 Next version is 1.0.0 2018-10-21 09:51:36 +08:00
khs1994
9919fd1c43 Add Fedora 2018-10-21 09:43:53 +08:00
khs1994
b955c79fb9 Merge pull request #359 from mahuihuang/fix-etcd 2018-09-14 16:50:51 +08:00
Ma Huihuang
1fdb8da844 添加环境变量
`No help topic for 'put'·
2018-09-14 16:42:45 +08:00
khs1994
a43bbd4f44 Merge pull request #358 from ujnzxw/master
fix typos
2018-09-08 11:10:35 +08:00
Xiaowei ZHAO
cbe21e28ec fix typos 2018-09-08 02:24:38 +00:00
khs1994
aa8adb4a36 Merge pull request #357 from LeonGravel/patch-1
fix typo
2018-09-06 22:08:40 +08:00
LeonGravel
7005ba3d88 fix typo 2018-09-06 14:43:10 +08:00
khs1994
276199aa37 Fix wordpress compose file volume format 2018-08-25 22:20:04 +08:00
khs1994
ee656ff4bb Update issue link 2018-08-14 09:30:08 +08:00
khs1994
c6ac96b64e Update Ubuntu LTS version to 18.04, Fix #352 2018-08-05 08:04:49 +08:00
khs1994
2e70663bf9 Change Docker CE update channels #351 2018-07-20 09:37:22 +08:00
康怀帅
80cb2445fc CA should put client host folder 2018-07-11 08:13:17 +08:00
康怀帅
c3c182e674 Fix registry tls error 2018-07-10 12:28:18 +08:00
khs1994
fb66c7e5ee Update demo image version 2018-07-10 08:09:43 +08:00
khs1994
8f46e579f4 Update etcd 2018-07-10 08:08:34 +08:00
khs1994
c6c0a6f1fe Remove -v description 2018-07-10 08:08:21 +08:00
khs1994
9f08baaa5c Update install 2018-07-10 08:07:31 +08:00
康怀帅
7bbc556e6e Remove aliyun daocloud 2018-06-28 11:15:25 +08:00
Baohua Yang
c6118d511d Merge pull request #347 from Tuvie/master
Fix mismatch between outline and title
2018-06-21 13:59:56 +08:00
Li Zhaogeng
d242aaf10e Fix a dismatch between table of contents and contents 2018-06-21 11:46:41 +08:00
康怀帅
113b5c2d20 Update README.md 2018-06-03 21:41:17 +08:00
康怀帅
b97e5e2a8b Update Docker version [skip ci] 2018-06-03 21:39:52 +08:00
康怀帅
54a8025903 Merge pull request #344 from edxi/patch-1
host file
2018-06-03 21:34:51 +08:00
Xi ErDe
02d4c5704c host file 2018-06-03 21:28:31 +08:00
denwork
e0791a61a2 Create nexus3_registry.md 2018-05-31 18:30:41 +08:00
Baohua Yang
5002488c24 Merge pull request #339 from khs1994-docker/master
Update Swarm mode: add rolling_update
2018-05-23 22:54:33 +08:00
康怀帅
20f19cbafd Update docker machine on windows 10
* Set up an external network switch. If you plan at any point to use Docker Machine to set up multiple local VMs, you need this anyway, as described in the topic on the Hyper-V driver for Docker Machine.

* https://docs.docker.com/machine/drivers/hyper-v/#example
2018-05-23 17:45:41 +08:00
khs1994
86d532630f Update Swarm mode: add rolling_update 2018-05-23 17:18:42 +08:00
康怀帅
fcd9f49e24 Update raspberry-pi content Fix #337 2018-05-10 08:09:39 +08:00
康怀帅
255292cc01 Change docker rmi TO docker image rm #279 2018-05-09 19:45:51 +08:00
Baohua Yang
9b9ab2349a Update gitbook link 2018-05-07 16:42:04 +08:00
Baohua Yang
122df6f233 Update gitbook read link 2018-04-29 15:46:38 +08:00
Shude Li
274cb33e89 doc(compose_file): fix version number of secrets (#332) 2018-04-22 09:04:30 -07:00
康怀帅
ed816ba448 Merge pull request #330 from songjiayang/master
fix typo
2018-04-17 19:08:53 +08:00
songjiayang
ca01158e1c fix typo 2018-04-17 17:40:50 +08:00
康怀帅
60fb624a40 Merge pull request #329 from khs1994-docker/master
Remove deprecated content
2018-04-08 21:03:00 +08:00
khs1994
58c6540cdf Remove deprecated content 2018-04-08 21:00:11 +08:00
康怀帅
79702eb956 Merge pull request #327 from khs1994-docker/master
Add some file
2018-04-08 20:36:47 +08:00
khs1994
fed0d4f65b Add some file 2018-04-08 01:06:53 +08:00
康怀帅
79801a2389 Update docker version 2018-03-31 19:22:16 +08:00
康怀帅
c753f3b509 Merge pull request #326 from Alex-WZ/patch-1
Update concepts.md
2018-03-31 15:39:59 +08:00
Alex-WZ
9187715bf0 Update concepts.md
知道容器的生命周期结束或者其被删除 -> 直到容器的生命周期结束或者其被删除
2018-03-31 14:36:42 +08:00
Baohua Yang
85f22aff35 Merge pull request #324 from thomaszdxsn/patch-1
Fix a typo
2018-03-30 21:58:35 +08:00
Yang,Zhou
4c2acb419b fix a typo 2018-03-30 20:55:02 +08:00
康怀帅
5cfe40a504 Fix docker login docker ce 18.04-rc1+
* https://docs.docker.com/engine/reference/commandline/login/
2018-03-30 10:04:01 +08:00
康怀帅
107b14d6bb Merge pull request #323 from YL2014/master
Fix 文字错误 拉去 -> 拉取
2018-03-22 13:04:46 +08:00
yl2014
717abe60e7 Fix 文字错误 拉去 -> 拉取 2018-03-22 12:31:35 +08:00
Baohua Yang
0ccdc3fcfe Minor update expression 2018-03-21 14:59:25 +08:00
康怀帅
2c9acf141c Update Contents
* Fix offlineread docker image

* Add warning on install

* Update install follow official
2018-03-19 16:04:23 +08:00
康怀帅
4abfa103b6 Merge pull request #321 from khs1994/master
Update Dockerfile multistage-builds #320
2018-03-10 09:18:54 +08:00
khs1994
0db00b9669 Update Dockerfile multistage-builds #320 2018-03-10 09:16:43 +08:00
康怀帅
7594e11f23 Update Compose README
Remove cluster
2018-03-10 08:45:09 +08:00
康怀帅
d58af9ad64 Merge pull request #319 from khs1994/master
Update Swarm mode create #302
2018-03-10 08:36:20 +08:00
khs1994
3b59591f14 Update Swarm mode create #302 2018-03-10 08:34:46 +08:00
康怀帅
53e917bb08 Merge pull request #316 from khs1994/master
Update install
2018-03-08 08:25:55 +08:00
khs1994
9deb181814 Update install 2018-03-08 08:23:35 +08:00
khs1994
37a9ed4b3b Update macOS mirror #313 2018-02-10 18:00:14 +08:00
康怀帅
81ec7190d6 Update offline read
Update offline read  (#312)
2018-01-23 21:52:14 +08:00
康怀帅
4667ffb091 Merge pull request #309 from khs1994/master
Change command docker ps to docker container ls
2018-01-16 16:31:05 +08:00
khs1994
3face791c6 Change command docker ps to docker container ls #279 2018-01-15 22:00:53 +08:00
康怀帅
3de028af98 Remove content 2018-01-15 09:21:09 +08:00
康怀帅
24a24306ae Update QQ Group status 2018-01-13 00:38:30 +08:00
康怀帅
dcb821d56b Update ISSUE_TEMPLATE.md 2018-01-13 00:34:33 +08:00
康怀帅
2d4841b764 Update offline 2018-01-05 19:00:22 +08:00
康怀帅
d83d89f927 Merge pull request #308 from khs1994/master
Update gitbook
2018-01-04 16:18:49 +08:00
khs1994
45e6dadac8 Update README.md about download pdf and epub [skip ci] 2018-01-04 16:16:09 +08:00
khs1994
be6840b9c2 Add cover in root 2018-01-04 15:41:34 +08:00
康怀帅
8a276c8595 Fix git url error 2018-01-03 01:08:24 +08:00
Baohua Yang
8aa5ac4172 Merge pull request #306 from khs1994/master
Release v0.9.0
2017-12-31 21:10:11 +08:00
khs1994
eb081e5dfa Release v0.9.0 2017-12-31 14:35:48 +08:00
khs1994
36b793408b Update faq 2017-12-31 14:27:55 +08:00
khs1994
6822561fd1 Update appendix repo wordpress 2017-12-31 14:26:03 +08:00
khs1994
cb18e6f08f Change debian to alpine 2017-12-31 14:20:04 +08:00
khs1994
5f32d8f5ea Fix spelling error 2017-12-31 10:33:52 +08:00
khs1994
c2f14bb2da Update project docker image Dockerfile 2017-12-31 10:30:53 +08:00
khs1994
dddfcf2832 Add shell script for offline read 2017-12-31 10:29:51 +08:00
Baohua Yang
c5c8b7d20a Update introduction and read links 2017-12-31 09:44:51 +08:00
康怀帅
c726aa30df Fix spelling error 2017-12-29 09:22:07 +08:00
康怀帅
42317a359d Merge pull request #303 from shawxr/patch-1
Update bind-mounts.md
2017-12-26 16:13:52 +08:00
康怀帅
8a43919e51 Update bind-mounts.md 2017-12-26 16:12:28 +08:00
shawxr
7753df7681 Update bind-mounts.md 2017-12-26 16:05:26 +08:00
Baohua Yang
5603887437 Merge pull request #300 from khs1994/master
Update content
2017-12-25 21:12:58 +08:00
康怀帅
d307ac54f6 Update advanced_network 2017-12-20 23:49:49 +08:00
khs1994
8589701bea Update volume 2017-12-20 23:46:55 +08:00
khs1994
b2e0b720ac Update registry 2017-12-20 23:46:46 +08:00
khs1994
9d196a2022 Update image 2017-12-20 23:45:25 +08:00
khs1994
1ea4934758 Update swarm mode 2017-12-20 23:44:38 +08:00
khs1994
b2427b1742 Add tips #265 2017-12-20 23:44:09 +08:00
Baohua Yang
b41d564c01 Merge pull request #299 from khs1994/master
Update mesos/framework.md
2017-12-20 21:37:17 +08:00
khs1994
d9fe0cc0d4 Update install 2017-12-20 10:24:36 +08:00
khs1994
19f8ec9654 Update mesos/framework.md 2017-12-20 10:14:53 +08:00
康怀帅
38070099d8 Update framework.md 2017-12-19 18:11:08 +08:00
康怀帅
c3bc7b124b Merge pull request #298 from ysykzheng/master
fix link
2017-12-19 18:10:02 +08:00
康怀帅
c0fb7f3af0 Update framework.md 2017-12-19 18:08:52 +08:00
ysykzheng
4fa76da7f8 fix link 2017-12-19 16:33:37 +08:00
Baohua Yang
a614374641 Merge pull request #297 from khs1994/master
User docker exec to enter container
2017-12-18 16:44:42 +08:00
khs1994
8f92f3b114 Remove some content in data_management 2017-12-17 23:02:42 +08:00
khs1994
7d7b4f2afc Rename enter.md to attach_exec.md 2017-12-17 22:57:11 +08:00
Baohua Yang
ba0b55101c Merge pull request #296 from khs1994/master 2017-12-17 13:39:32 +08:00
khs1994
95d063dbd1 Update compose 2017-12-16 15:08:02 +08:00
康怀帅
047755b702 Update content (#294) 2017-12-16 13:56:57 +08:00
Baohua Yang
654737a396 Merge pull request #292 from khs1994/master 2017-12-13 10:44:19 +08:00
khs1994
8615cbf286 Add registry auth TLS #180 2017-12-11 20:22:51 +08:00
khs1994
154a42bd69 Fix error:secret to config 2017-12-11 17:44:48 +08:00
Baohua Yang
e6291d57f9 Merge pull request #291 from khs1994/master 2017-12-10 15:09:26 +08:00
khs1994
e9c9b8391d Update install: add logout and login user after install 2017-12-10 13:21:52 +08:00
khs1994
3ab7f6dfb8 Update docker-compose.yml 2017-12-10 12:53:57 +08:00
khs1994
a3267d1b3a Update book.json [skip ci] 2017-12-10 12:41:08 +08:00
khs1994
8dbaa7ea33 Update cloud: add images 2017-12-10 12:19:24 +08:00
khs1994
8939af4f97 Update compose #288 2017-12-10 11:52:09 +08:00
khs1994
6bcce7e562 Remove img 2017-12-10 11:00:24 +08:00
khs1994
6af58b6c4a Move DNS to network #278 2017-12-10 10:51:40 +08:00
184 changed files with 3517 additions and 2394 deletions

View File

@@ -1,17 +1,15 @@
workspace:
base: /srv/gitbook-src
path: .
pipeline:
build:
image: yeasy/docker_practice:latest
# pull: true
environment:
- TZ=Asia/Shanghai
secrets: [key1, key2]
commands:
# - echo $${key1}
# - echo $KEY2
- docker-entrypoint.sh build
when:
event: [push, pull_request, tag, deployment]
branch: master
kind: pipeline
type: docker
name: build
steps:
- name: build
image: yeasy/docker_practice:latest
pull: if-not-exists # always never
environment:
TZ: Asia/Shanghai
commands:
- docker-entrypoint.sh build
trigger:
branch:
- master

29
.editorconfig Normal file
View File

@@ -0,0 +1,29 @@
# EditorConfig is awesome: https://EditorConfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
[*.py]
indent_size = 4
[Makefile]
indent_style = tab

5
.gitattributes vendored Normal file
View File

@@ -0,0 +1,5 @@
* text=auto
*.sh text eol=lf
* linguist-language=go

View File

@@ -1,29 +0,0 @@
* [ ] Have u googled the problem? If no, pls do that first!
### Environment
<!--请提供环境信息包括操作系统版本等-->
<!--Provides env info like OS version-->
* [x] Linux
* [x] CentOS 7
* [ ] Ubuntu 16.04
* [ ] Ubuntu 17.10
* [ ] Debian 9
* [ ] Debian 8
* [ ] CoreOS
* [ ] macOS
* [ ] Windows 10
* [ ] Raspberry Pi (ARM)
* [ ] Others (Pls describe below)
### Docker Version
<!--如果你的 Docker 版本低于 17.09 请尽可能升级到该版本-->
<!--if Docker version under 17.09, please upgrade Docker to 17.09-->
* [x] 17.11 Edge
* [ ] 17.09 Stable
* [ ] 1.13.0 or Before
### Problem Description
<!--描述你的问题请贴出操作步骤终端报错日志-->
<!--describe problem with detailed steps and logs-->

41
.github/ISSUE_TEMPLATE/Bug_report.md vendored Normal file
View File

@@ -0,0 +1,41 @@
---
name: Bug report
about: Create a report to help us improve
---
* [ ] Have u googled the problem? If no, pls do that first!
### Environment
<!--请提供环境信息包括操作系统版本等保留你的操作系统其他选项删除-->
<!--Provides env info like OS version-->
* [x] Linux
* [x] CentOS 7
* [x] Fedora
* [x] Ubuntu 16.04 +
* [x] Debian 9 +
* [x] macOS
* [x] Windows 10
* [x] Raspberry Pi (ARM)
* [x] Others (Pls describe below)
### Docker Version
<!--如果你的 Docker 版本低于 19.03 请尽可能升级到该版本保留你的 Docker 版本其他选项删除-->
<!--if Docker version under 19.03, please upgrade Docker to 19.03-->
* [x] Edge (v19.03)
* [x] Stable (v19.03)
* [x] 1.13.0 or Before
### Problem Description
<!--描述你的问题请贴出操作步骤终端报错截图或文字信息-->
<!--describe problem with detailed steps and logs-->
<!--提交问题之前请点击预览标签符合要求之后再提交问题-->

41
.github/ISSUE_TEMPLATE/Custom.md vendored Normal file
View File

@@ -0,0 +1,41 @@
---
name: Custom issue template
about: Create a issue about Docker
---
* [ ] Have u googled the problem? If no, pls do that first!
### Environment
<!--请提供环境信息包括操作系统版本等保留你的操作系统其他选项删除-->
<!--Provides env info like OS version-->
* [x] Linux
* [x] CentOS 7
* [x] Fedora
* [x] Ubuntu 16.04 +
* [x] Debian 9 +
* [x] macOS
* [x] Windows 10
* [x] Raspberry Pi (ARM)
* [x] Others (Pls describe below)
### Docker Version
<!--如果你的 Docker 版本低于 19.03 请尽可能升级到该版本保留你的 Docker 版本其他选项删除-->
<!--if Docker version under 19.03, please upgrade Docker to 19.03-->
* [x] Edge (v19.03)
* [x] Stable (v19.03)
* [x] 1.13.0 or Before
### Problem Description
<!--描述你的问题请贴出操作步骤终端报错截图或文字信息-->
<!--describe problem with detailed steps and logs-->
<!--提交问题之前请点击预览标签符合要求之后再提交问题-->

View File

@@ -0,0 +1,5 @@
---
name: Feature request
about: Suggest an idea for docker_practice
---

View File

@@ -1,20 +1,20 @@
<!--
Thanks for your contribution.
Thanks for your contribution.
See [CONTRIBUTING](CONTRIBUTING.md) for contribution guidelines.
-->
### Proposed changes (Mandatory)
<!--
Tell us what you did and why:
Tell us what you did and why:
One line short description
And details in other paragraphs.
-->
### Fix issues (Optional)
<!--
Tell us what issues you fixed, e.g., fix #123
Tell us what issues you fixed, e.g., fix #123
-->

18
.github/workflows/ci.yaml vendored Normal file
View File

@@ -0,0 +1,18 @@
on:
push:
pull_request:
name: CI
jobs:
build:
name: Build GitBook
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 2
- name: Build
uses: docker://yeasy/docker_practice
with:
args: build

View File

@@ -1,7 +1,8 @@
language: bash
sudo: required
services:
- docker
before_install:
- openssl aes-256-cbc -K $encrypted_6cc8cff04075_key -iv $encrypted_6cc8cff04075_iv
-in .travis/id_rsa.enc -out ~/.ssh/id_rsa -d
@@ -10,27 +11,43 @@ before_install:
- date
- git config --global user.name "khs1994"
- git config --global user.email "khs1994@khs1994.com"
script:
- docker run -it --rm -v $PWD:/srv/gitbook-src yeasy/docker_practice build
after_success:
- sudo chmod -R 777 _book
- echo "FROM nginx:alpine" >> Dockerfile
- echo "COPY _book /usr/share/nginx/html" >> Dockerfile
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker build -t dockerpracticesig/docker_practice:us-en .
- docker run -dit --rm -p 4000:80 dockerpracticesig/docker_practice:us-en
- sleep 5
- curl 127.0.0.1:4000
- docker push dockerpracticesig/docker_practice:us-en
- cd _book
- git init
- git remote add origin "$REPO"
- git remote add origin "$DEPLOY_REPO"
- git add .
- COMMIT=`date "+%F %T"`
- git commit -m "Travis CI Site updated $COMMIT"
- git push -f origin master:"$DEPLOY_BRANCH"
env:
global:
- DEPLOY_BRANCH: pages
# - DEPLOY_BRANCH: legacy-pages
- REPO: git@github.com:yeasy/docker_practice.git
- DEPLOY_BRANCH: master
- DEPLOY_REPO: git@github.com:docker-practice/us-en.git
addons:
ssh_known_hosts:
- github.com
branches:
only:
- master
- dev
# - docker-legacy
- english

View File

@@ -1,4 +1,4 @@
FROM node:9-alpine
FROM node:alpine
ENV TZ=Asia/Shanghai

View File

@@ -10,8 +10,9 @@
"plugins": [
"-livereload",
"image-captions",
"github-buttons",
"page-treeview"
"github",
"page-treeview@2.9.8",
"editlink"
],
"pluginsConfig": {
"image-captions": {
@@ -20,13 +21,12 @@
},
"caption": "图 _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_ - _CAPTION_"
},
"github-buttons": {
"buttons": [{
"user": "yeasy",
"repo": "docker_practice",
"type": "star",
"size": "small"
}]
"github": {
"url": "https://github.com/yeasy/docker_practice"
},
"editlink": {
"base": "https://github.com/yeasy/docker_practice/blob/master/",
"label": "编辑本页"
},
"page-treeview": {
"copyright": "Copyright &#169; yeasy",

View File

@@ -6,13 +6,15 @@ if [ $1 = "sh" ];then sh ; exit 0; fi
rm -rf node_modules _book
cp -a . ../gitbook
srcDir=$PWD
cd ../gitbook
cp -a . /srv/gitbook
cd /srv/gitbook
main(){
if [ "$1" = build ];then gitbook build; cp -a _book ../gitbook-src; echo $START; date "+%F %T"; exit 0; fi
gitbook serve
if [ "$1" = build ];then gitbook build && cp -a _book $srcDir && echo $START && date "+%F %T" && exit 0; fi
exec gitbook serve
exit 0
}

View File

@@ -1,10 +1,20 @@
## 主要修订记录
* 0.9: 2017-12-31
* 1.1.0 2019-12-31
* 全面支持 v19.x 新版本
* 增加 `BuildKit`
* 增加 `docker manifest` 命令使用说明
* 移除 `Ubuntu 14.04` `Debian 8` `Debian 7`
* 0.9-rc3: 2017-12-20
* 1.0.0: 2018-12-31
* 全面支持 v18.x 新版本
* 添加如何调试 Docker
* 错误修正
* 0.9-rc2: 2017-12-10
* 0.9.0: 2017-12-31
* v1.13.x 旧版本的最后支持
* 0.9.0-rc2: 2017-12-10
* 增加 Docker 中文资源链接
* 增加介绍基于 Docker CI/CD 工具 `Drone`
@@ -29,7 +39,7 @@
* 修复内容逻辑错误
* 修复`404` 链接
* 0.9-rc1: 2017-11-29
* 0.9.0-rc1: 2017-11-29
* 根据最新版本v17.09修订内容
@@ -88,23 +98,23 @@
* 0.3.0: 2014-11-25
* 完成仓库章节
* 重写安全章节
* 修正底层实现章节的架构命名空间控制组文件系统容器格式等内容
* 添加对常见仓库和镜像的介绍
* 添加 Dockerfile 的介绍
* 重新校订中英文混排格式
* 修订文字表达
* 发布繁体版本分支zh-Hant
* 完成仓库章节
* 重写安全章节
* 修正底层实现章节的架构命名空间控制组文件系统容器格式等内容
* 添加对常见仓库和镜像的介绍
* 添加 Dockerfile 的介绍
* 重新校订中英文混排格式
* 修订文字表达
* 发布繁体版本分支zh-Hant
* 0.2.0: 2014-09-18
* 对照官方文档重写介绍基本概念安装镜像容器仓库数据管理网络等章节
* 添加底层实现章节
* 添加命令查询和资源链接章节
* 其它修正
* 对照官方文档重写介绍基本概念安装镜像容器仓库数据管理网络等章节
* 添加底层实现章节
* 添加命令查询和资源链接章节
* 其它修正
* 0.1.0: 2014-09-05
* 添加基本内容;
* 修正错别字和表达不通顺的地方
* 添加基本内容
* 修正错别字和表达不通顺的地方

View File

@@ -6,17 +6,19 @@
```bash
$ git clone git@github.com:docker_user/docker_practice.git
$ cd docker_practice
$ git config user.name "yourname"
$ git config user.email "your email"
```
修改代码后提交并推送到自己的仓库注意修改提交消息为对应 Issue 号和描述
```bash
# Update the content
$ git commit -a -s
# In commit msg dialog, add content like "Fix issue #235: describe ur change"
$ git push
```
@@ -26,9 +28,11 @@ $ git push
```bash
$ git remote add upstream https://github.com/yeasy/docker_practice
$ git fetch upstream
$ git checkout master
$ git rebase upstream/master
$ git push -f origin master
```

View File

@@ -1,29 +1,41 @@
# Docker 从入门到实践
# Docker 从入门到实践英文版
[![](https://img.shields.io/github/stars/yeasy/docker_practice.svg?style=social&label=Stars)](https://github.com/yeasy/docker_practice) [![](https://img.shields.io/docker/pulls/yeasy/docker_practice.svg)](https://store.docker.com/community/images/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://badges.gitter.im/docker_practice/Lobby.svg)](https://gitter.im/docker_practice/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![](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)
0.9-rc1(2017-11-29)
**v1.1.0**
*修订说明本书内容将基于 Docker CE v17.x 进行重新修订计划 2017 年底发布 0.9.0 版本旧版本Docker 1.13-内容请阅读 [docker-legacy](https://github.com/yeasy/docker_practice/tree/docker-legacy) 分支的内容。*
| 语言 | 构建状态 | - |
| :------------- | :------------- | :--- |
| [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) |
| [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](http://www.docker.com) 是个划时代的开源项目,它彻底释放了计算虚拟化的威力,极大提高了应用的运行效率,降低了云计算资源供应的成本!使用 Docker可以让应用的部署、测试和分发都变得前所未有的高效和轻松
[Docker](https://www.docker.com) 是个划时代的开源项目,它彻底释放了计算虚拟化的威力,极大提高了应用的维护效率,降低了云计算应用开发的成本!使用 Docker可以让应用的部署、测试和分发都变得前所未有的高效和轻松
无论是应用开发者运维人员还是其他信息技术从业人员都有必要认识和掌握 Docker节约有限的时间
无论是应用开发者运维人员还是其他信息技术从业人员都有必要认识和掌握 Docker节约有限的生命
本书既适用于具备基础 Linux 知识的 Docker 初学者也希望可供理解原理和实现的高级用户参考同时书中给出的实践案例可供在进行实际部署时借鉴前六章为基础内容供用户理解 Docker 的基本概念和操作7 ~ 9 章介绍一些高级操作 10 章给出典型的应用场景和实践案例1112 介绍关于 Docker 安全和实现技术等高级话题后续章节则分别介绍一些相关热门开源项目
本书既适用于具备基础 Linux 知识的 Docker 初学者也希望可供理解原理和实现的高级用户参考同时书中给出的实践案例可供在进行实际部署时借鉴前六章为基础内容供用户理解 Docker 的基本概念和操作7 ~ 9 章介绍包括数据管理网络等高级操作 10 ~ 13 章介绍了容器生态中的几个核心项目1415 讨论了关于 Docker 安全和实现技术等高级话题后续章节则分别介绍包括 EtcdCoreOSKubernetesMesos容器云等相关热门开源项目最后还展示了使用容器技术的典型的应用场景和实践案例
* 在线阅读[GitBook](https://www.gitbook.io/book/yeasy/docker_practice) 或 [Github](https://github.com/yeasy/docker_practice/blob/master/SUMMARY.md)
* [国内镜像](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)
* [离线阅读](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)
* pdf 版本 [下载](https://www.gitbook.com/download/pdf/book/yeasy/docker_practice)
* epub 版本 [下载](https://www.gitbook.com/download/epub/book/yeasy/docker_practice)
* 在线阅读[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)
* [离线阅读 `$ 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)
Docker 自身仍在快速发展中生态环境也在蓬勃成长建议初学者使用最新 Docker (v17.x) 进行学习实践欢迎 [参与维护项目](CONTRIBUTING.md)
Docker 自身仍在快速发展中生态环境也在蓬勃成长建议初学者使用最新稳定版本 Docker 进行学习实践欢迎 [参与项目维护](CONTRIBUTING.md)
* [修订记录](CHANGELOG.md)
* [贡献者名单](https://github.com/yeasy/docker_practice/graphs/contributors)
## 微信小程序
<p align="center">
<img width="200" src="https://user-images.githubusercontent.com/16733187/49682252-3ac4c500-faec-11e8-86ab-eafe0139be6b.jpg">
</p>
<p align="center"><strong>微信扫码 随时随地阅读~</strong></p>
## 技术交流
欢迎加入 Docker 技术交流 QQ 分享 Docker 资源交流 Docker 技术
* QQ I 已满341410255
@@ -37,16 +49,21 @@ Docker 自身仍在快速发展中,生态环境也在蓬勃成长。建议初
* QQ IX 已满571502246
* QQ X 可加145983035
>如果有问题请通过 [Issues](https://github.com/yeasy/docker_practice/issues/new/choose) 来提出。
## 进阶学习
![](https://github.com/yeasy/docker_practice/raw/master/_images/docker_primer2.png)
[Docker 技术入门与实战](http://item.jd.com/12121728.html)》第二版已经正式出版,针对初版进行内容升级,欢迎大家阅读使用并反馈建议。
[![](https://github.com/yeasy/docker_practice/raw/master/_images/docker_primer3.png)](https://union-click.jd.com/jdc?e=&p=AyIGZRtYFAcXBFIZWR0yEgRQH1kXAhs3EUQDS10iXhBeGlcJDBkNXg9JHU4YDk5ER1xOGRNLGEEcVV8BXURFUFdfC0RVU1JRUy1OVxUBFwNXGVscMlVYLlAaXAV1Z1JHA0dWEHVXZTliY1QLWStaJQAWB10fXhwKEDdlG1wlUHzf462DsLMO0%2F%2BUjp2VIgZlG18RBBcCUBlbEAoTBWUcWxwySVI7HAhBBxEOBUgOFQYQUGUraxYyIjdVK1glQHxXUEhYEVEUUFQcC0IHGgRRSAgVARAPAhsLFgNCDl0ZWiUAEwZREg%3D%3D&t=W1dCFFlQCxxKQgFHREkdSVJKSQVJHFRXFk9FUlpGQUpLCVBaTFhbXQtWVmpSWRtYEAYQBVUS)
* [京东图书](https://item.jd.com/12121728.html)
* [China-Pub](http://product.china-pub.com/5089907)
[Docker 技术入门与实战](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)
## 鼓励项目
欢迎鼓励项目一杯 coffee~
<p align="center">
<img width="200" src="https://github.com/yeasy/docker_practice/raw/master/_images/donate.jpeg">
</p>
![](https://github.com/yeasy/docker_practice/raw/master/_images/donate.jpeg)
<p align="center"><strong>欢迎鼓励项目一杯 coffee~</strong></p>

View File

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

BIN
_images/docker_primer3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View File

@@ -1,9 +1,12 @@
# 高级网络配置
>注意本章属于 `Docker` 高级配置如果您是初学者您可以暂时跳过本章节直接学习 [Docker Compose](../compose) 一节
本章将介绍 Docker 的一些高级网络配置和选项
Docker 启动时会自动在主机上创建一个 `docker0` 虚拟网桥实际上是 Linux 的一个 bridge可以理解为一个软件交换机它会在挂载到它的网口之间进行转发
同时Docker 随机分配一个本地未占用的私有网段 [RFC1918](http://tools.ietf.org/html/rfc1918) 中定义)中的一个地址给 `docker0` 接口。比如典型的 `172.17.42.1`,掩码为 `255.255.0.0`。此后启动的容器内的网口也会自动分配一个同一网段(`172.17.0.0/16`)的地址。
同时Docker 随机分配一个本地未占用的私有网段 [RFC1918](https://tools.ietf.org/html/rfc1918) 中定义)中的一个地址给 `docker0` 接口。比如典型的 `172.17.42.1`,掩码为 `255.255.0.0`。此后启动的容器内的网口也会自动分配一个同一网段(`172.17.0.0/16`)的地址。
当创建一个 Docker 容器的时候同时会创建了一对 `veth pair` 接口当数据包发送到一个接口时另外一个接口也可以收到相同的数据包这对接口一端在容器内 `eth0`另一端在本地并被挂载到 `docker0` 网桥名称以 `veth` 开头例如 `vethAQI2QT`通过这种方式主机可以跟容器通信容器之间也可以相互通信Docker 就创建了在主机和所有容器之间一个虚拟共享网络

View File

@@ -20,9 +20,9 @@ $sysctl -w net.ipv4.ip_forward=1
* 本地系统的防火墙软件 -- `iptables` 是否允许通过
#### 访问所有端口
当启动 Docker 服务时候默认会添加一条转发策略到 iptables FORWARD 链上策略为通过`ACCEPT`还是禁止`DROP`取决于配置`--icc=true`缺省值还是 `--icc=false`当然如果手动指定 `--iptables=false` 则不会添加 `iptables` 规则
当启动 Docker 服务 dockerd时候默认会添加一条转发策略到本地主机 iptables FORWARD 链上策略为通过`ACCEPT`还是禁止`DROP`取决于配置`--icc=true`缺省值还是 `--icc=false`当然如果手动指定 `--iptables=false` 则不会添加 `iptables` 规则
可见默认情况下不同容器之间是允许网络互通的如果为了安全考虑可以在 `/etc/default/docker` 文件中配置 `DOCKER_OPTS=--icc=false` 来禁止它
可见默认情况下不同容器之间是允许网络互通的如果为了安全考虑可以在 `/etc/docker/daemon.json` 文件中配置 `{"icc": false}` 来禁止它
#### 访问指定端口
在通过 `-icc=false` 关闭网络访问后还可以通过 `--link=CONTAINER_NAME:ALIAS` 选项来访问容器的开放端口

View File

@@ -1,5 +1,5 @@
## 编辑网络配置文件
Docker 1.2.0 开始支持在运行中的容器里编辑 `/etc/hosts`, `/etc/hostname` `/etc/resolve.conf` 文件
Docker 1.2.0 开始支持在运行中的容器里编辑 `/etc/hosts`, `/etc/hostname` `/etc/resolv.conf` 文件
但是这些修改是临时的只在运行的容器中保留容器终止或重启后并不会被保存下来也不会被 `docker commit` 提交
但是这些修改是临时的只在运行的容器中保留容器终止或重启后并不会被保存下来也不会被 `docker commit` 提交

View File

@@ -1,344 +1 @@
# Dockerfile 最佳实践
本附录是笔者对 Docker 官方文档中 [Best practices for writing Dockerfiles](https://docs.docker.com/engine/userguide/eng-image/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` 镜像的例子
```docker
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
尽可能使用当前官方仓库作为你构建镜像的基础推荐使用 [Debian](https://hub.docker.com/_/debian/) 镜像,因为它被严格控制并保持最小尺寸(目前小于 150 mb但它仍然是一个完整的发行版。
### LABEL
你可以给镜像添加标签来帮助组织镜像记录许可信息辅助自动化构建等每个标签一行 `LABEL` 开头加上一个或多个标签对下面的示例展示了各种不同的可能格式`#` 开头的行是注释内容
>注意如果你的字符串中包含空格必须将字符串放入引号中或者对空格使用转义如果字符串内容本身就包含引号必须对引号使用转义
```docker
# 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` 指令中
```docker
# 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/engine/userguide/labels-custom-metadata/)。关于查询标签信息,参考 [Managing labels on objects](https://docs.docker.com/engine/userguide/labels-custom-metadata/#managing-labels-on-objects)。
### 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` 声明例如
```docker
RUN apt-get update && apt-get install -y \
package-bar \
package-baz \
package-foo
```
`apt-get update` 放在一条单独的 `RUN` 声明中会导致缓存问题以及后续的 `apt-get install` 失败比如假设你有一个 `Dockerfile` 文件
```docker
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y curl
```
构建镜像后所有的层都在 Docker 的缓存中假设你后来又修改了其中的 `apt-get install` 添加了一个包
```docker
FROM ubuntu:14.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`这就是所谓的固定版本例如
```docker
RUN apt-get update && apt-get install -y \
package-bar \
package-baz \
package-foo=1.3.*
```
固定版本会迫使构建过程检索特定的版本而不管缓存中有什么这项技术也可以减少因所需包中未预料到的变化而导致的失败
下面是一个 `RUN` 指令的示例模板展示了所有关于 `apt-get` 的建议
```docker
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` 也能用于设置常见的版本号比如下面的示例
```docker
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` 所有文件这将保证每个步骤的构建缓存只在特定的文件变化时失效例如
```docker
COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt
COPY . /tmp/
```
如果将 `COPY . /tmp/` 放置在 `RUN` 指令之前只要 `.` 目录中任何一个文件变化都会导致后续指令的缓存失效
为了让镜像尽量小最好不要使用 `ADD` 指令从远程 URL 获取包而是使用 `curl` `wget`这样你可以在文件提取完之后删掉不再需要的文件来避免在镜像中额外添加一层比如尽量避免下面的用法
```docker
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
```
而是应该使用下面这种方法
```docker
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`:
```docker
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` 执行
```docker
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
# [Best practices for writing Dockerfiles](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/)

View File

@@ -12,118 +12,118 @@ Docker 命令有两大类,客户端命令和服务端命令。前者是主要
## 客户端命令选项
* --config=""指定客户端配置文件默认为 `/.docker`
* -D=true|false是否使用 debug 模式默认不开启
* -H, --host=[]指定命令对应 Docker 守护进程的监听接口可以为 unix 套接字unix:///path/to/socket文件句柄fd://socketfd或 tcp 套接字(tcp://[host[:port]]),默认为 unix:///var/run/docker.sock
* -l, --log-level="debug|info|warn|error|fatal"指定日志输出级别
* --tls=true|false是否对 Docker 守护进程启用 TLS 安全机制默认为否
* --tlscacert= /.docker/ca.pemTLS CA 签名的可信证书文件路径
* --tlscert= /.docker/cert.pemTLS 可信证书文件路径
* --tlscert= /.docker/key.pemTLS 密钥文件路径
* --tlsverify=true|false启用 TLS 校验默认为否
* `--config=""`指定客户端配置文件默认为 `~/.docker`
* `-D=true|false`是否使用 debug 模式默认不开启
* `-H, --host=[]`指定命令对应 Docker 守护进程的监听接口可以为 unix 套接字 `unix:///path/to/socket`文件句柄 `fd://socketfd` tcp 套接字 `tcp://[host[:port]]`默认为 `unix:///var/run/docker.sock`
* `-l, --log-level="debug|info|warn|error|fatal"`指定日志输出级别
* `--tls=true|false`是否对 Docker 守护进程启用 TLS 安全机制默认为否
* `--tlscacert=/.docker/ca.pem`TLS CA 签名的可信证书文件路径
* `--tlscert=/.docker/cert.pem`TLS 可信证书文件路径
* `--tlscert=/.docker/key.pem`TLS 密钥文件路径
* `--tlsverify=true|false`启用 TLS 校验默认为否
## dockerd 命令选项
* --api-cors-header=""CORS 头部域默认不允许 CORS要允许任意的跨域访问可以指定为 *
* --authorization-plugin=""载入认证的插件
* -b=""将容器挂载到一个已存在的网桥上指定为 'none' 时则禁用容器的网络 --bip 选项互斥
* --bip=""让动态创建的 docker0 网桥采用给定的 CIDR 地址; -b 选项互斥
* --cgroup-parent=""指定 cgroup 的父组默认 fs cgroup 驱动为 `/docker`systemd cgroup 驱动为 `system.slice`
* --cluster-store=""构成集群 Swarm集群键值数据库服务地址
* --cluster-advertise=""构成集群时自身的被访问地址可以为 `host:port` `interface:port`
* --cluster-store-opt=""构成集群时键值数据库的配置选项
* --config-file="/etc/docker/daemon.json"daemon 配置文件路径
* --containerd=""containerd 文件的路径
* -D, --debug=true|false是否使用 Debug 模式缺省为 false
* --default-gateway=""容器的 IPv4 网关地址必须在网桥的子网段内
* --default-gateway-v6=""容器的 IPv6 网关地址
* --default-ulimit=[]默认的 ulimit
* --disable-legacy-registry=true|false是否允许访问旧版本的镜像仓库服务器
* --dns=""指定容器使用的 DNS 服务器地址
* --dns-opt=""DNS 选项
* --dns-search=[]DNS 搜索域
* --exec-opt=[]运行时的执行选项
* --exec-root=""容器执行状态文件的根路径默认为 `/var/run/docker`
* --fixed-cidr=""限定分配 IPv4 地址范围
* --fixed-cidr-v6=""限定分配 IPv6 地址范围
* -G, --group=""分配给 unix 套接字的组默认为 `docker`
* -g, --graph=""Docker 运行时的根路径默认为 `/var/lib/docker`
* -H, --host=[]指定命令对应 Docker daemon 的监听接口可以为 unix 套接字unix:///path/to/socket文件句柄fd://socketfd或 tcp 套接字(tcp://[host[:port]]),默认为 unix:///var/run/docker.sock
* --icc=true|false是否启用容器间以及跟 daemon 所在主机的通信默认为 true
* --insecure-registry=[]允许访问给定的非安全仓库服务
* --ip=""绑定容器端口时候的默认 IP 地址缺省为 0.0.0.0
* --ip-forward=true|false是否检查启动在 Docker 主机上的启用 IP 转发服务默认开启注意关闭该选项将不对系统转发能力进行任何检查修改
* --ip-masq=true|false是否进行地址伪装用于容器访问外部网络默认开启
* --iptables=true|false是否允许 Docker 添加 iptables 规则缺省为 true
* --ipv6=true|false是否启用 IPv6 支持默认关闭
* -l, --log-level="debug|info|warn|error|fatal"指定日志输出级别
* --label="[]"添加指定的键值对标注
* --log-driver="json-file|syslog|journald|gelf|fluentd|awslogs|splunk|etwlogs|gcplogs|none"指定日志后端驱动默认为 json-file
* --log-opt=[]日志后端的选项
* --mtu=VALUE指定容器网络的 mtu
* -p=""指定 daemon PID 文件路径缺省为 `/var/run/docker.pid`
* --raw-logs输出原始未加色彩的日志信息
* --registry-mirror=<scheme>://<host>:指定 `docker pull` 时使用的注册服务器镜像地址;
* -s, --storage-driver=""指定使用给定的存储后端
* --selinux-enabled=true|false是否启用 SELinux 支持缺省值为 falseSELinux 目前尚不支持 overlay 存储驱动
* --storage-opt=[]驱动后端选项
* --tls=true|false是否对 Docker daemon 启用 TLS 安全机制默认为否
* --tlscacert= /.docker/ca.pemTLS CA 签名的可信证书文件路径
* --tlscert= /.docker/cert.pemTLS 可信证书文件路径
* --tlscert= /.docker/key.pemTLS 密钥文件路径
* --tlsverify=true|false启用 TLS 校验默认为否
* --userland-proxy=true|false是否使用用户态代理来实现容器间和出容器的回环通信默认为 true
* --userns-remap=default|uid:gid|user:group|user|uid指定容器的用户命名空间默认是创建新的 UID GID 映射到容器内进程
* `--api-cors-header=""`CORS 头部域默认不允许 CORS要允许任意的跨域访问可以指定为 "*"
* `--authorization-plugin=""`载入认证的插件
* `-b=""`将容器挂载到一个已存在的网桥上指定为 `none` 时则禁用容器的网络 `--bip` 选项互斥
* `--bip=""`让动态创建的 `docker0` 网桥采用给定的 CIDR 地址; `-b` 选项互斥
* `--cgroup-parent=""`指定 cgroup 的父组默认 fs cgroup 驱动为 `/docker`systemd cgroup 驱动为 `system.slice`
* `--cluster-store=""`构成集群 `Swarm`集群键值数据库服务地址
* `--cluster-advertise=""`构成集群时自身的被访问地址可以为 `host:port` `interface:port`
* `--cluster-store-opt=""`构成集群时键值数据库的配置选项
* `--config-file="/etc/docker/daemon.json"`daemon 配置文件路径
* `--containerd=""`containerd 文件的路径
* `-D, --debug=true|false`是否使用 Debug 模式缺省为 false
* `--default-gateway=""`容器的 IPv4 网关地址必须在网桥的子网段内
* `--default-gateway-v6=""`容器的 IPv6 网关地址
* `--default-ulimit=[]`默认的 ulimit
* `--disable-legacy-registry=true|false`是否允许访问旧版本的镜像仓库服务器
* `--dns=""`指定容器使用的 DNS 服务器地址
* `--dns-opt=""`DNS 选项
* `--dns-search=[]`DNS 搜索域
* `--exec-opt=[]`运行时的执行选项
* `--exec-root=""`容器执行状态文件的根路径默认为 `/var/run/docker`
* `--fixed-cidr=""`限定分配 IPv4 地址范围
* `--fixed-cidr-v6=""`限定分配 IPv6 地址范围
* `-G, --group=""`分配给 unix 套接字的组默认为 `docker`
* `-g, --graph=""`Docker 运行时的根路径默认为 `/var/lib/docker`
* `-H, --host=[]`指定命令对应 Docker daemon 的监听接口可以为 unix 套接字 `unix:///path/to/socket`文件句柄 `fd://socketfd` tcp 套接字 `tcp://[host[:port]]`默认为 `unix:///var/run/docker.sock`
* `--icc=true|false`是否启用容器间以及跟 daemon 所在主机的通信默认为 true
* `--insecure-registry=[]`允许访问给定的非安全仓库服务
* `--ip=""`绑定容器端口时候的默认 IP 地址缺省为 `0.0.0.0`
* `--ip-forward=true|false`是否检查启动在 Docker 主机上的启用 IP 转发服务默认开启注意关闭该选项将不对系统转发能力进行任何检查修改
* `--ip-masq=true|false`是否进行地址伪装用于容器访问外部网络默认开启
* `--iptables=true|false`是否允许 Docker 添加 iptables 规则缺省为 true
* `--ipv6=true|false`是否启用 IPv6 支持默认关闭
* `-l, --log-level="debug|info|warn|error|fatal"`指定日志输出级别
* `--label="[]"`添加指定的键值对标注
* `--log-driver="json-file|syslog|journald|gelf|fluentd|awslogs|splunk|etwlogs|gcplogs|none"`指定日志后端驱动默认为 `json-file`
* `--log-opt=[]`日志后端的选项
* `--mtu=VALUE`指定容器网络的 `mtu`
* `-p=""`指定 daemon PID 文件路径缺省为 `/var/run/docker.pid`
* `--raw-logs`输出原始未加色彩的日志信息
* `--registry-mirror=<scheme>://<host>`指定 `docker pull` 时使用的注册服务器镜像地址
* `-s, --storage-driver=""`指定使用给定的存储后端
* `--selinux-enabled=true|false`是否启用 SELinux 支持缺省值为 falseSELinux 目前尚不支持 overlay 存储驱动
* `--storage-opt=[]`驱动后端选项
* `--tls=true|false`是否对 Docker daemon 启用 TLS 安全机制默认为否
* `--tlscacert=/.docker/ca.pem`TLS CA 签名的可信证书文件路径
* `--tlscert=/.docker/cert.pem`TLS 可信证书文件路径
* `--tlscert=/.docker/key.pem`TLS 密钥文件路径
* `--tlsverify=true|false`启用 TLS 校验默认为否
* `--userland-proxy=true|false`是否使用用户态代理来实现容器间和出容器的回环通信默认为 true
* `--userns-remap=default|uid:gid|user:group|user|uid`指定容器的用户命名空间默认是创建新的 UID GID 映射到容器内进程
## 客户端命令
可以通过 `docker COMMAND --help` 来查看这些命令的具体用法
* attach依附到一个正在运行的容器中
* build从一个 Dockerfile 创建一个镜像
* commit从一个容器的修改中创建一个新的镜像
* cp在容器和本地宿主系统之间复制文件中
* create创建一个新容器但并不运行它
* diff检查一个容器内文件系统的修改包括修改和增加
* events从服务端获取实时的事件
* exec在运行的容器内执行命令
* export导出容器内容为一个 tar
* history显示一个镜像的历史信息
* images列出存在的镜像
* import导入一个文件典型为 tar 路径或目录来创建一个本地镜像
* info显示一些相关的系统信息
* inspect显示一个容器的具体配置信息
* kill关闭一个运行中的容器 (包括进程和所有相关资源)
* load从一个 tar 包中加载一个镜像
* login注册或登录到一个 Docker 的仓库服务器
* logout Docker 的仓库服务器登出
* logs获取容器的 log 信息
* network管理 Docker 的网络包括查看创建删除挂载卸载等
* node管理 swarm 集群中的节点包括查看更新删除提升/取消管理节点等
* pause暂停一个容器中的所有进程
* port查找一个 nat 到一个私有网口的公共口
* ps列出主机上的容器
* pull从一个Docker的仓库服务器下拉一个镜像或仓库
* push将一个镜像或者仓库推送到一个 Docker 的注册服务器
* rename重命名一个容器
* restart重启一个运行中的容器
* rm删除给定的若干个容器
* rmi删除给定的若干个镜像
* run创建一个新容器并在其中运行给定命令
* save保存一个镜像为 tar 包文件
* search Docker index 中搜索一个镜像
* service管理 Docker 所启动的应用服务包括创建更新删除等
* start启动一个容器
* stats输出一个或多个容器的资源使用统计信息
* stop终止一个运行中的容器
* swarm管理 Docker swarm 集群包括创建加入退出更新等
* tag为一个镜像打标签
* top查看一个容器中的正在运行的进程信息
* unpause将一个容器内所有的进程从暂停状态中恢复
* update更新指定的若干容器的配置信息
* version输出 Docker 的版本信息
* volume管理 Docker volume包括查看创建删除等
* wait阻塞直到一个容器终止然后输出它的退出符
* `attach`依附到一个正在运行的容器中
* `build`从一个 Dockerfile 创建一个镜像
* `commit`从一个容器的修改中创建一个新的镜像
* `cp`在容器和本地宿主系统之间复制文件中
* `create`创建一个新容器但并不运行它
* `diff`检查一个容器内文件系统的修改包括修改和增加
* `events`从服务端获取实时的事件
* `exec`在运行的容器内执行命令
* `export`导出容器内容为一个 `tar`
* `history`显示一个镜像的历史信息
* `images`列出存在的镜像
* `import`导入一个文件典型为 `tar` 路径或目录来创建一个本地镜像
* `info`显示一些相关的系统信息
* `inspect`显示一个容器的具体配置信息
* `kill`关闭一个运行中的容器 (包括进程和所有相关资源)
* `load`从一个 tar 包中加载一个镜像
* `login`注册或登录到一个 Docker 的仓库服务器
* `logout` Docker 的仓库服务器登出
* `logs`获取容器的 log 信息
* `network`管理 Docker 的网络包括查看创建删除挂载卸载等
* `node`管理 swarm 集群中的节点包括查看更新删除提升/取消管理节点等
* `pause`暂停一个容器中的所有进程
* `port`查找一个 nat 到一个私有网口的公共口
* `ps`列出主机上的容器
* `pull`从一个Docker的仓库服务器下拉一个镜像或仓库
* `push`将一个镜像或者仓库推送到一个 Docker 的注册服务器
* `rename`重命名一个容器
* `restart`重启一个运行中的容器
* `rm`删除给定的若干个容器
* `rmi`删除给定的若干个镜像
* `run`创建一个新容器并在其中运行给定命令
* `save`保存一个镜像为 tar 包文件
* `search` Docker index 中搜索一个镜像
* `service`管理 Docker 所启动的应用服务包括创建更新删除等
* `start`启动一个容器
* `stats`输出一个或多个容器的资源使用统计信息
* `stop`终止一个运行中的容器
* `swarm`管理 Docker swarm 集群包括创建加入退出更新等
* `tag`为一个镜像打标签
* `top`查看一个容器中的正在运行的进程信息
* `unpause`将一个容器内所有的进程从暂停状态中恢复
* `update`更新指定的若干容器的配置信息
* `version`输出 Docker 的版本信息
* `volume`管理 Docker volume包括查看创建删除等
* `wait`阻塞直到一个容器终止然后输出它的退出符
## 一张图总结 Docker 的命令
![Docker 命令总结](../_images/cmd_logic.png)

42
appendix/debug.md Normal file
View File

@@ -0,0 +1,42 @@
# 如何调试 Docker
## 开启 Debug 模式
dockerd 配置文件 daemon.json默认位于 /etc/docker/中添加
```json
{
"debug": true
}
```
重启守护进程
```bash
$ sudo kill -SIGHUP $(pidof dockerd)
```
此时 dockerd 会在日志中输入更多信息供分析
## 检查内核日志
```bash
$ sudo dmesag |grep dockerd
$ sudo dmesag |grep runc
```
## Docker 不响应时处理
可以杀死 dockerd 进程查看其堆栈调用情况
```bash
$ sudo kill -SIGUSR1 $(pidof dockerd)
```
## 重置 Docker 本地数据
*注意本操作会移除所有的 Docker 本地数据包括镜像和容器等*
```bash
$ sudo rm -rf /var/lib/docker
```

View File

@@ -12,13 +12,13 @@
### 本地的镜像文件都存放在哪里
Docker 相关的本地资源存放在 `/var/lib/docker/` 目录下 `aufs` 文件系统为例其中 `container` 目录存放容器信息`graph` 目录存放镜像信息`aufs` 目录下存放具体的镜像层文件
Docker 相关的本地资源默认存放在 `/var/lib/docker/` 目录下 `aufs` 文件系统为例其中 `container` 目录存放容器信息`graph` 目录存放镜像信息`aufs` 目录下存放具体的镜像层文件
### 构建 Docker 镜像应该遵循哪些原则
整体原则上尽量保持镜像功能的明确和内容的精简要点包括
* 尽量选取满足需求但较小的基础系统镜像例如大部分时候可以选择 debian:wheezy debian:jessie 镜像仅有不足百兆大小
* 尽量选取满足需求但较小的基础系统镜像例如大部分时候可以选择 debian:wheezy debian:stretch 镜像仅有不足百兆大小
* 清理编译生成文件安装包的缓存等临时文件
@@ -30,7 +30,7 @@
* 使用 Dockerfile 创建镜像时候要添加 .dockerignore 文件或使用干净的工作目录
更多内容请查看 [Dockerfile 最佳实践](https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/)
更多内容请查看 [Dockerfile 最佳实践](../best_practices.md)
### 碰到网络问题无法 pull 镜像命令行指定 http_proxy 无效
@@ -38,13 +38,13 @@
## 容器相关
### 容器退出后通过 docker ps 命令查看不到数据会丢失么
### 容器退出后通过 docker container ls 命令查看不到数据会丢失么
容器退出后会处于终止exited状态此时可以通过 `docker ps -a` 查看其中的数据也不会丢失还可以通过 `docker start` 命令来启动它只有删除掉容器才会清除所有数据
容器退出后会处于终止exited状态此时可以通过 `docker container ls -a` 查看其中的数据也不会丢失还可以通过 `docker start` 命令来启动它只有删除掉容器才会清除所有数据
### 如何停止所有正在运行的容器
可以使用 `docker kill $(docker ps -q)` 命令
可以使用 `docker stop $(docker container ls -q)` 命令
### 如何批量清理已经停止的容器
@@ -82,7 +82,7 @@ $ docker run --network=my-net --ip=172.25.3.3 -itd --name=my-container busybox
### 可以在一个容器中同时运行多个应用进程么
一般并不推荐在同一个容器内运行多个应用进程如果有类似需求可以通过一些额外的进程管理机制比如 `supervisord` 来管理所运行的进程可以参考 https://docs.docker.com/engine/admin/multi-service_container/ 。
一般并不推荐在同一个容器内运行多个应用进程如果有类似需求可以通过一些额外的进程管理机制比如 `supervisord` 来管理所运行的进程可以参考 https://docs.docker.com/config/containers/multi-service_container/ 。
### 如何控制容器占用系统资源CPU内存的份额
@@ -96,27 +96,16 @@ $ docker run --network=my-net --ip=172.25.3.3 -itd --name=my-container busybox
注册服务器是存放实际的镜像文件的地方注册索引则负责维护用户的账号权限搜索标签等的管理因此注册服务器利用注册索引来实现认证等管理
### 从非官方仓库例如 non-official-repo.com下载镜像时候有时候会提示Error: Invalid registry endpoint https://non-official-repo.com/v1/……”?
Docker 1.3.0 版本往后加强了对镜像安全性的验证需要添加私有仓库证书或者手动添加对非官方仓库的信任
编辑 Docker 配置文件在其中添加
```sh
DOCKER_OPTS="--insecure-registry non-official-repo"
```
之后重启 Docker 服务即可
## 配置相关
### Docker 的配置文件放在哪里如何修改配置
使用 `upstart` 的系统 Ubuntu 14.04的配置文件在 `/etc/default/docker`使用 `systemd` 的系统 Ubuntu 16.04Centos 的配置文件在 `/etc/docker/daemon.json`
使用 `systemd` 的系统 Ubuntu 16.04Centos 的配置文件在 `/etc/docker/daemon.json`
### 如何更改 Docker 的默认存储位置
Docker 的默认存储位置是 `/var/lib/docker`如果希望将 Docker 的本地文件存储到其他分区可以使用 Linux 软连接的方式来完成或者在启动 daemon 时通过 `-g` 参数指定
Docker 的默认存储位置是 `/var/lib/docker`如果希望将 Docker 的本地文件存储到其他分区可以使用 Linux 软连接的方式来完成或者在启动 daemon 时通过 `-g` 参数指定或者修改配置文件 `/etc/docker/daemon.json` "data-root" 可以使用 `docker system info | grep "Root Dir"` 查看当前使用的存储位置
例如如下操作将默认存储位置迁移到 /storage/docker
@@ -137,7 +126,7 @@ lrwxrwxrwx. 1 root root 15 11月 17 13:43 docker -> /storage/docker
[root@s26 lib]# service docker start
```
### 使用内存和 swap 限制启动容器时候报警告WARNING: Your kernel does not support cgroup swap limit. WARNING: Your kernel does not support swap limit capabilities. Limitation discarded.
### 使用内存和 swap 限制启动容器时候报警告"WARNING: Your kernel does not support cgroup swap limit. WARNING: Your kernel does not support swap limit capabilities. Limitation discarded."
这是因为系统默认没有开启对内存和 swap 使用的统计功能引入该功能会带来性能的下降要开启该功能可以采取如下操作

View File

@@ -1,10 +1,10 @@
## [CentOS](https://store.docker.com/images/centos/)
## [CentOS](https://hub.docker.com/_/centos)
### 基本信息
[CentOS](https://en.wikipedia.org/wiki/CentOS) 是流行的 Linux 发行版,其软件包大多跟 RedHat 系列保持一致。
该仓库位于 https://store.docker.com/images/centos/ ,提供了 CentOS 从 5 ~ 7 各个版本的镜像。
该仓库位于 `https://hub.docker.com/_/centos` 提供了 CentOS 5 ~ 7 各个版本的镜像
### 使用方法

View File

@@ -1,10 +1,10 @@
## [MongoDB](https://store.docker.com/images/mongo/)
## [MongoDB](https://hub.docker.com/_/mongo/)
### 基本信息
[MongoDB](https://en.wikipedia.org/wiki/MongoDB) 是开源的 NoSQL 数据库实现。
该仓库位于 https://store.docker.com/images/mongo/ ,提供了 MongoDB 2.x ~ 3.x 各个版本的镜像。
该仓库位于 `https://hub.docker.com/_/mongo/` 提供了 MongoDB 2.x ~ 4.x 各个版本的镜像
### 使用方法

View File

@@ -1,10 +1,10 @@
## [MySQL](https://store.docker.com/images/mysql/)
## [MySQL](https://hub.docker.com/_/mysql/)
### 基本信息
[MySQL](https://en.wikipedia.org/wiki/MySQL) 是开源的关系数据库实现。
该仓库位于 https://store.docker.com/images/mysql/ ,提供了 MySQL 5.5 ~ 8.x 各个版本的镜像。
该仓库位于 `https://hub.docker.com/_/mysql/` 提供了 MySQL 5.5 ~ 8.x 各个版本的镜像
### 使用方法
@@ -20,7 +20,7 @@ $ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql
$ docker run --name some-app --link some-mysql:mysql -d application-that-uses-mysql
```
或者通过 `mysql`
或者通过 `mysql` 命令行连接
```bash
$ docker run -it --rm \

View File

@@ -1,10 +1,10 @@
## [Nginx](https://store.docker.com/images/nginx/)
## [Nginx](https://hub.docker.com/_/nginx/)
### 基本信息
[Nginx](https://en.wikipedia.org/wiki/Nginx) 是开源的高效的 Web 服务器实现,支持 HTTP、HTTPS、SMTP、POP3、IMAP 等协议。
该仓库位于 https://store.docker.com/images/nginx/ ,提供了 Nginx 1.0 ~ 1.13.x 各个版本的镜像。
该仓库位于 `https://hub.docker.com/_/nginx/` 提供了 Nginx 1.0 ~ 1.17.x 各个版本的镜像
### 使用方法

View File

@@ -1,10 +1,10 @@
## [Node.js](https://store.docker.com/images/node/)
## [Node.js](https://hub.docker.com/_/node/)
### 基本信息
[Node.js](https://en.wikipedia.org/wiki/Node.js) 是基于 JavaScript 的可扩展服务端和网络软件开发平台。
该仓库位于 https://store.docker.com/images/node/ ,提供了 Node.js 0.10 ~ 9.x 各个版本的镜像。
该仓库位于 `https://hub.docker.com/_/node/` 提供了 Node.js 0.10 ~ 12.x 各个版本的镜像
### 使用方法

19
appendix/repo/php.md Normal file
View File

@@ -0,0 +1,19 @@
## [PHP](https://hub.docker.com/_/php/)
### 基本信息
[PHP](https://en.wikipedia.org/wiki/php)Hypertext Preprocessor 超文本预处理器的字母缩写)是一种被广泛应用的开放源代码的多用途脚本语言,它可嵌入到 HTML 中,尤其适合 web 开发。
该仓库位于 `https://hub.docker.com/_/php/` 提供了 PHP 5.x ~ 7.x 各个版本的镜像
### 使用方法
下面的命令将运行一个已有的 PHP 脚本
```bash
$ docker run -it --rm -v "$PWD":/app -w /app php:alpine php your-script.php
```
### Dockerfile
请到 https://github.com/docker-library/docs/tree/master/php 查看。

View File

@@ -1,23 +1,23 @@
## [Redis](https://store.docker.com/images/redis/)
## [Redis](https://hub.docker.com/_/redis/)
### 基本信息
[Redis](https://en.wikipedia.org/wiki/Redis) 是开源的内存 Key-Value 数据库实现。
该仓库位于 https://store.docker.com/images/redis/ ,提供了 Redis 3.x ~ 4.x 各个版本的镜像。
该仓库位于 `https://hub.docker.com/_/redis/` 提供了 Redis 3.x ~ 5.x 各个版本的镜像
### 使用方法
默认会在 `6379` 端口启动数据库
```bash
$ docker run --name some-redis -d redis
$ docker run --name some-redis -d -p 6379:6379 redis
```
另外还可以启用 [持久存储](http://redis.io/topics/persistence)。
另外还可以启用 [持久存储](https://redis.io/topics/persistence)。
```bash
$ docker run --name some-redis -d redis redis-server --appendonly yes
$ docker run --name some-redis -d -p 6379:6379 redis redis-server --appendonly yes
```
默认数据存储位置在 `VOLUME/data`可以使用 `--volumes-from some-volume-container` `-v /docker/host/dir:/data` 将数据存放到本地

View File

@@ -1,17 +1,17 @@
## [Ubuntu](https://store.docker.com/images/ubuntu/)
## [Ubuntu](https://hub.docker.com/_/ubuntu/)
### 基本信息
[Ubuntu](https://en.wikipedia.org/wiki/Ubuntu) 是流行的 Linux 发行版,其自带软件版本往往较新一些。
该仓库位于 https://store.docker.com/images/ubuntu/ ,提供了 Ubuntu 从 12.04 ~ 18.04 各个版本的镜像。
该仓库位于 `https://hub.docker.com/_/ubuntu/` 提供了 Ubuntu 12.04 ~ 19.04 各个版本的镜像
### 使用方法
默认会启动一个最小化的 Ubuntu 环境
```bash
$ docker run --name some-ubuntu -it ubuntu:17.10
$ docker run --name some-ubuntu -it ubuntu:18.04
root@523c70904d54:/#
```

View File

@@ -1,10 +1,10 @@
## [WordPress](https://store.docker.com/images/wordpress/)
## [WordPress](https://hub.docker.com/_/wordpress/)
### 基本信息
[WordPress](https://en.wikipedia.org/wiki/WordPress) 是开源的 Blog 和内容管理系统框架,它基于 PHP 和 MySQL。
该仓库位于 https://store.docker.com/images/wordpress/ ,提供了 WordPress 4.x 版本的镜像。
该仓库位于 `https://hub.docker.com/_/wordpress/` 提供了 WordPress 4.x ~ 5.x 版本的镜像
### 使用方法
@@ -14,12 +14,11 @@
$ docker run --name some-wordpress --link some-mysql:mysql -d wordpress
```
启动 WordPress 容器时可以指定的一些环境参数包括
启动 WordPress 容器时可以指定的一些环境变量包括
* `-e WORDPRESS_DB_USER=...` 缺省为 root
* `-e WORDPRESS_DB_PASSWORD=...` 缺省为连接 mysql 容器的环境变量 `MYSQL_ROOT_PASSWORD` 的值
* `-e WORDPRESS_DB_NAME=...` 缺省为 wordpress
* `-e WORDPRESS_AUTH_KEY=...`, `-e WORDPRESS_SECURE_AUTH_KEY=...`, `-e WORDPRESS_LOGGED_IN_KEY=...`, `-e WORDPRESS_NONCE_KEY=...`, `-e WORDPRESS_AUTH_SALT=...`, `-e WORDPRESS_SECURE_AUTH_SALT=...`, `-e WORDPRESS_LOGGED_IN_SALT=...`, `-e WORDPRESS_NONCE_SALT=...` 缺省为随机 sha1
* `WORDPRESS_DB_USER` 缺省为 `root`
* `WORDPRESS_DB_PASSWORD` 缺省为连接 mysql 容器的环境变量 `MYSQL_ROOT_PASSWORD` 的值
* `WORDPRESS_DB_NAME` 缺省为 `wordpress`
### Dockerfile

View File

@@ -5,8 +5,6 @@
* Docker 官方主页https://www.docker.com
* Docker 官方博客https://blog.docker.com/
* Docker 官方文档https://docs.docker.com/
* Docker Storehttps://store.docker.com
* Docker Cloudhttps://cloud.docker.com
* Docker Hubhttps://hub.docker.com
* Docker 的源代码仓库https://github.com/moby/moby
* Docker 发布版本历史https://docs.docker.com/release-notes/

View File

@@ -1,5 +0,0 @@
# Docker 中文资源
* [Docker 问答录100 ](https://blog.lab99.org/post/docker-2016-07-14-faq.html)
* [Docker CE 变更日志中文翻译](https://github.com/allencloud/docker-changelog-chinese)

View File

@@ -1,7 +1,7 @@
# 基本概念
Docker 包括三个基本概念
* 镜像`Image`
* 容器`Container`
* 仓库`Repository`
# Basic Concepts
Docker contains 3 basic concepts
* `Image`
* `Container`
* `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:16.04` 就包含了完整的一套 Ubuntu 16.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](../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://store.docker.com/images/ubuntu) 为例,`ubuntu` 是仓库的名字,其内包含有不同的版本标签,如,`14.04`, `16.04`。我们可以通过 `ubuntu:14.04`,或者 `ubuntu:16.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](http://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 下载速度会提高很多。在 [安装 Dcoekr](../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://store.docker.com/images/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甚至提供了用户界面以及一些高级功能比如[VMWare Harbor](https://github.com/vmware/harbor) [Sonatype Nexus](https://www.sonatype.com/docker)。
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",
"language": "zh-hans",
"language": "en",
"links": {
"sidebar": {
"GitHub": "https://github.com/yeasy/docker_practice"
@@ -10,23 +10,22 @@
"plugins": [
"-livereload",
"image-captions",
"github-buttons",
"page-treeview"
"github",
"page-treeview@2.9.8",
"editlink"
],
"pluginsConfig": {
"image-captions": {
"attributes": {
"width": "600"
},
"caption": " _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_ - _CAPTION_"
"caption": "Image _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_ - _CAPTION_"
},
"github-buttons": {
"buttons": [{
"user": "yeasy",
"repo": "docker_practice",
"type": "star",
"size": "small"
}]
"github": {
"url": "https://github.com/yeasy/docker_practice"
},
"editlink": {
"base": "https://github.com/yeasy/docker_practice/blob/english/"
},
"page-treeview": {
"copyright": "Copyright &#169; yeasy",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

View File

@@ -0,0 +1,28 @@
# GitHub Actions
GitGub Actions GitHub 推出的一款 CI/CD 工具
我们可以在每个 job step 中使用 Docker 执行构建步骤
```yaml
on: push
name: CI
jobs:
my-job:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 2
- name: run docker container
uses: docker://golang:alpine
with:
args: go version
```
## 参考资料
* [Actions Docs](https://help.github.com/en/categories/automating-your-workflow-with-github-actions)

View File

@@ -1,17 +0,0 @@
workspace:
base: /srv/drone-demo
path: .
pipeline:
build:
image: golang:alpine
# pull: true
environment:
- KEY=VALUE
secrets: [key1, key2]
commands:
# - echo $$KEY
- pwd
- ls
- CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
- ./app

View File

@@ -1,35 +0,0 @@
version: '3'
services:
drone-server:
image: drone/drone:0.8-alpine
ports:
- 443:443
# - "${PRO_PUBLIC_IP}:8000:8000"
volumes:
- drone-data:/var/lib/drone/:rw
# - ${SSL_PATH}:/etc/certs
restart: always
environment:
- DRONE_SECRET=drone
- DRONE_OPEN=false
- DRONE_ADMIN=GITHUB_SERNAME
- DRONE_HOST=https://drone.yeasy.com
- DRONE_GITHUB=true
- DRONE_GITHUB_CLIENT=${DRONE_GITHUB_CLIENT_PRO}
- DRONE_GITHUB_SECRET=${DRONE_GITHUB_SECRET_PRO}
drone-agent:
image: drone/agent:0.8-alpine
restart: always
depends_on:
- drone-server
volumes:
- /var/run/docker.sock:/var/run/docker.sock:rw
environment:
- DRONE_SECRET=drone
- DRONE_SERVER=drone-server:9000
dns: 114.114.114.114
volumes:
drone-data:

View File

@@ -1,183 +0,0 @@
## Drone
基于 `Docker` `CI/CD` 工具 `Drone` 所有编译测试的流程都在 `Docker` 容器中进行
开发者只需在项目中包含 `.drone.yml` 文件将代码推送到 git 仓库`Drone` 就能够自动化的进行编译测试发布
本小节以 `GitHub` + `Drone` 来演示 `Drone` 的工作流程当然在实际开发过程中你的代码也许不在 GitHub 托管那么你可以尝试使用 `Gogs` + `Drone` 来进行 `CI/CD`
### 要求
* 拥有公网 IP域名 (如果你不满足要求可以尝试在本地使用 Gogs + Drone)
* 域名 SSL 证书 (目前国内有很多云服务商提供免费证书)
* 熟悉 `Docker` 以及 `Docker Compose`
* 熟悉 `Git` 基本命令
* `CI/CD` 有一定了解
### 新建 GitHub 应用
登录 GitHub https://github.com/settings/applications/new 新建一个应用。
![](../.image/drone-github.png)
接下来查看这个应用的详情记录 `Client ID` `Client Secret`之后配置 Drone 会用到
### 配置 Drone
我们通过使用 `Docker Compose` 来启动 `Drone`编写 `docker-compose.yml` 文件
```yaml
version: '3'
services:
drone-server:
image: drone/drone:0.8-alpine
ports:
- 443:443
# - "${PRO_PUBLIC_IP}:8000:8000"
volumes:
- drone-data:/var/lib/drone/:rw
- ${SSL_PATH}:/etc/certs:rw
restart: always
environment:
- DRONE_SECRET=drone
- DRONE_OPEN=false
- DRONE_ADMIN=${GITHUB_SERNAME}
- DRONE_HOST=${DRONE_HOST}
- DRONE_GITHUB=true
- DRONE_GITHUB_CLIENT=${DRONE_GITHUB_CLIENT}
- DRONE_GITHUB_SECRET=${DRONE_GITHUB_SECRET}
- DRONE_SERVER_CERT=/etc/certs/drone.domain.com.crt
- DRONE_SERVER_KEY=/etc/certs/drone.domain.com.key
drone-agent:
image: drone/agent:0.8-alpine
restart: always
depends_on:
- drone-server
volumes:
- /var/run/docker.sock:/var/run/docker.sock:rw
environment:
- DRONE_SECRET=drone
- DRONE_SERVER=drone-server:9000
dns: 114.114.114.114
volumes:
drone-data:
```
替换 `${SSL_PATH}` 为你网站的 SSL 证书路径
替换 `${GITHUB_SERNAME}` 为你 GitHub 的用户名该用户将成为 Drone 的管理员
替换 `${DRONE_HOST}` 为你部署 Drone 的域名
替换 `${DRONE_GITHUB_CLIENT}` 为你 GitHub 应用的 `Client ID`
替换 `${DRONE_GITHUB_SECRET}` 为你 GitHub 应用的 `Client Secret`
*注意* 如果你的服务器占用了 `443` 端口请配置 Nginx 代理这里不再赘述
#### 启动 Drone
```bash
$ docker-compose up -d
```
### Drone 关联项目
Github 新建一个名为 `drone-demo` 的仓库
打开我们已经部署好的 Drone 网站使用 GitHub 账号登录在界面中关联刚刚新建的 `drone-demo` 仓库
### 编写项目源代码
在本机初始化一个 git 仓库
```bash
$ mkdir drone-demo
$ cd drone-demo
$ git init
$ git remote add origin git@github.com/username/drone-demo.git
```
这里以一个简单的 `Go` 程序为例该程序输出 `Hello World!`
编写 `app.go` 文件
```go
package main
import "fmt"
func main(){
fmt.Printf("Hello World!");
}
```
编写 `.drone.yml` 文件
```yaml
workspace:
base: /srv/drone-demo
path: .
pipeline:
build:
image: golang:alpine
# pull: true
environment:
- KEY=VALUE
secrets: [key1, key2]
commands:
- echo $$KEY
- pwd
- ls
- CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
- ./app
```
`workspace` 指明 git 源代码克隆的目标路径本例中 git 源代码将被克隆到 golang 容器中的 `/srv/drone-demo` 目录中
`pipeline` 指明构建所需的 Docker 镜像环境变量编译指令等
现在目录结构如下
```bash
.
├── .drone.yml
└── app.go
```
### 推送项目源代码到 GitHub
```bash
$ git add .
$ git commit -m "test drone ci"
$ git push origin master
```
### 查看项目构建过程及结果
打开我们部署好的 `Drone` 网站即可看到构建结果
![](../.image/drone-build.png)
当然我们也可以把构建结果上传到 GitHubDocker Registry云服务商提供的对象存储或者生产环境中
本书 GitBook 也使用 Drone 进行 CI/CD具体配置信息请查看本书根目录 [`.drone.yml`](https://github.com/yeasy/docker_practice/blob/master/.drone.yml) 文件。
## 参考链接
* [Drone Github](https://github.com/drone/drone)
* [Drone 文档](http://docs.drone.io/)

View File

@@ -0,0 +1,6 @@
DRONE_SERVER_HOST=
DRONE_SERVER_PROTO=
DRONE_RPC_SECRET=
HOSTNAME=
DRONE_GITHUB_CLIENT_ID=
DRONE_GITHUB_CLIENT_SECRET=

2
cases/ci/drone/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.env
ssl/*

99
cases/ci/drone/README.md Normal file
View File

@@ -0,0 +1,99 @@
# Drone
基于 `Docker` `CI/CD` 工具 `Drone` 所有编译测试的流程都在 `Docker` 容器中进行
开发者只需在项目中包含 `.drone.yml` 文件将代码推送到 git 仓库`Drone` 就能够自动化的进行编译测试发布
本小节以 `GitHub` + `Drone` 来演示 `Drone` 的工作流程当然在实际开发过程中你的代码也许不在 GitHub 托管那么你可以尝试使用 `Gogs` + `Drone` 来进行 `CI/CD`
## Drone 关联项目
Github 新建一个名为 `drone-demo` 的仓库
打开我们已经 [部署好的 Drone 网站](install.md) 或者 [Drone Cloud](https://cloud.drone.io),使用 GitHub 账号登录,在界面中关联刚刚新建的 `drone-demo` 仓库。
## 编写项目源代码
初始化一个 git 仓库
```bash
$ mkdir drone-demo
$ cd drone-demo
$ git init
$ git remote add origin git@github.com:username/drone-demo.git
```
这里以一个简单的 `Go` 程序为例该程序输出 `Hello World!`
编写 `app.go` 文件
```go
package main
import "fmt"
func main(){
fmt.Printf("Hello World!\n");
}
```
编写 `.drone.yml` 文件
```yaml
kind: pipeline
type: docker
name: build
steps:
- name: build
image: golang:alpine
pull: if-not-exists # always never
environment:
KEY: VALUE
commands:
- echo $KEY
- pwd
- ls
- CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
- ./app
trigger:
branch:
- master
```
现在目录结构如下
```bash
.
├── .drone.yml
└── app.go
```
## 推送项目源代码到 GitHub
```bash
$ git add .
$ git commit -m "test drone ci"
$ git push origin master
```
## 查看项目构建过程及结果
打开我们部署好的 `Drone` 网站或者 Drone Cloud即可看到构建结果
![](../.image/drone-build.png)
当然我们也可以把构建结果上传到 GitHubDocker Registry云服务商提供的对象存储或者生产环境中
本书 GitBook 也使用 Drone 进行 CI/CD具体配置信息请查看本书根目录 [`.drone.yml`](https://github.com/yeasy/docker_practice/blob/master/.drone.yml) 文件。
## 参考链接
* [Drone Github](https://github.com/drone/drone)
* [Drone 文档](http://docs.drone.io/)
* [Drone 示例](https://github.com/docker-practice/drone-demo)

View File

@@ -0,0 +1,19 @@
kind: pipeline
type: docker
name: build
steps:
- name: build
image: golang:alpine
pull: if-not-exists # always never
environment:
KEY: VALUE
commands:
- echo $KEY
- pwd
- ls
- CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
- ./app
trigger:
branch:
- master

View File

@@ -0,0 +1 @@
# Drone Demo

View File

@@ -3,5 +3,5 @@ package main
import "fmt"
func main(){
fmt.Printf("Hello World!");
fmt.Printf("Hello World!\n");
}

View File

@@ -0,0 +1,39 @@
version: '3'
services:
drone-server:
image: drone/drone:1
ports:
- 443:443
- 80:80
volumes:
- drone-data:/data:rw
- ./ssl:/etc/certs
restart: always
environment:
- DRONE_AGENTS_ENABLED=true
- DRONE_SERVER_HOST=${DRONE_SERVER_HOST:-drone.domain.com}
- DRONE_SERVER_PROTO=${DRONE_SERVER_PROTO:-https}
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET:-secret}
- DRONE_GITHUB_SERVER=https://github.com
- DRONE_GITHUB_CLIENT_ID=${DRONE_GITHUB_CLIENT_ID}
- DRONE_GITHUB_CLIENT_SECRET=${DRONE_GITHUB_CLIENT_SECRET}
drone-agent:
image: drone/agent:1
restart: always
depends_on:
- drone-server
volumes:
- /var/run/docker.sock:/var/run/docker.sock:rw
environment:
- DRONE_RPC_PROTO=http
- DRONE_RPC_HOST=drone-server
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET:-secret}
- DRONE_RUNNER_NAME=${HOSTNAME:-demo}
- DRONE_RUNNER_CAPACITY=2
dns: 114.114.114.114
volumes:
drone-data:

87
cases/ci/drone/install.md Normal file
View File

@@ -0,0 +1,87 @@
# 部署 Drone
## 要求
* 拥有公网 IP域名 (如果你不满足要求可以尝试在本地使用 Gogs + Drone)
* 域名 SSL 证书 (目前国内有很多云服务商提供免费证书)
* 熟悉 `Docker` 以及 `Docker Compose`
* 熟悉 `Git` 基本命令
* `CI/CD` 有一定了解
## 新建 GitHub 应用
登录 GitHub https://github.com/settings/applications/new 新建一个应用。
![](https://docs.drone.io/screenshots/github_application_create.png)
接下来查看这个应用的详情记录 `Client ID` `Client Secret`之后配置 Drone 会用到
## 配置 Drone
我们通过使用 `Docker Compose` 来启动 `Drone`编写 `docker-compose.yml` 文件
```yaml
version: '3'
services:
drone-server:
image: drone/drone:1
ports:
- 443:443
- 80:80
volumes:
- drone-data:/data:rw
- ./ssl:/etc/certs
restart: always
environment:
- DRONE_AGENTS_ENABLED=true
- DRONE_SERVER_HOST=${DRONE_SERVER_HOST:-https://drone.yeasy.com}
- DRONE_SERVER_PROTO=${DRONE_SERVER_PROTO:-https}
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET:-secret}
- DRONE_GITHUB_SERVER=https://github.com
- DRONE_GITHUB_CLIENT_ID=${DRONE_GITHUB_CLIENT_ID}
- DRONE_GITHUB_CLIENT_SECRET=${DRONE_GITHUB_CLIENT_SECRET}
drone-agent:
image: drone/agent:1
restart: always
depends_on:
- drone-server
volumes:
- /var/run/docker.sock:/var/run/docker.sock:rw
environment:
- DRONE_RPC_PROTO=http
- DRONE_RPC_HOST=drone-server
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET:-secret}
- DRONE_RUNNER_NAME=${HOSTNAME:-demo}
- DRONE_RUNNER_CAPACITY=2
dns: 114.114.114.114
volumes:
drone-data:
```
新建 `.env` 文件输入变量及其值
```bash
# 必填 服务器地址,例如 drone.domain.com
DRONE_SERVER_HOST=
DRONE_SERVER_PROTO=https
DRONE_RPC_SECRET=secret
HOSTNAME=demo
# 必填 在 GitHub 应用页面查看
DRONE_GITHUB_CLIENT_ID=
# 必填 在 GitHub 应用页面查看
DRONE_GITHUB_CLIENT_SECRET=
```
### 启动 Drone
```bash
$ docker-compose up -d
```

47
cases/ci/travis/README.md Normal file
View File

@@ -0,0 +1,47 @@
## Travis CI 中使用 Docker
当代码提交到 GitHub [Travis CI](https://travis-ci.com/) 会根据项目根目录 `.travis.yml` 文件设置的指令,执行一系列操作。
本小节介绍如何在 Travis CI 中使用 Docker 进行持续集成/持续部署CI/CD这里以当代码提交到 GitHub 时自动构建 Docker 镜像并推送到 Docker Hub 为例进行介绍
### 准备
首先登录 https://travis-ci.com/account/repositories 选择 GitHub 仓库,按照指引安装 GitHub App 来启用 GitHub 仓库构建。
在项目根目录新建一个 `Dockerfile` 文件
```dockerfile
FROM alpine
RUN echo "Hello World"
```
新建 Travis CI 配置文件 `.travis.yml` 文件
```yml
language: bash
dist: xenial
services:
- docker
before_script:
# 登录到 docker hub
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
script:
# 这里编写测试代码的命令
- echo "test code"
after_success:
# 当代码测试通过后执行的命令
- docker build -t username/alpine .
- docker push username/alpine
```
> 请提前在 Travis CI 仓库设置页面配置 `DOCKER_PASSWORD` `DOCKER_USERNAME` 变量
### 查看结果
将项目推送到 GitHub, 登录 [Travis CI](https://travis-ci.com/) 查看构建详情。

View File

@@ -0,0 +1,16 @@
language: bash
dist: xenial
services:
- docker
before_script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
script:
- echo "test code"
after_success:
- docker build -t username/alpine .
- docker push username/alpine

View File

@@ -0,0 +1,3 @@
FROM alpine
RUN echo "Hello World"

View File

@@ -56,7 +56,7 @@ $ apk --update add --no-cache <package>
### 相关资源
* `Alpine` 官网http://alpinelinux.org/
* `Alpine` 官网https://www.alpinelinux.org/
* `Alpine` 官方仓库https://github.com/alpinelinux
* `Alpine` 官方镜像https://hub.docker.com/_/alpine/
* `Alpine` 官方镜像仓库https://github.com/gliderlabs/docker-alpine

View File

@@ -70,7 +70,7 @@ Fedora release 24 (Twenty Four)
* `Fedora` 官方仓库https://github.com/fedora-infra
* `Fedora` 官方镜像https://hub.docker.com/_/fedora/
* `Fedora` 官方镜像仓库https://github.com/fedora-cloud/docker-brew-fedora
* `CentOS` 官网https://getfedora.org/
* `CentOS` 官网https://www.centos.org
* `CentOS` 官方仓库https://github.com/CentOS
* `CentOS` 官方镜像https://hub.docker.com/_/centos/
* `CentOS` 官方镜像仓库https://github.com/CentOS/CentOS-Dockerfiles

View File

@@ -44,10 +44,10 @@ Ubuntu 是一个以桌面应用为主的GNU/Linux操作系统其名称来自
#### 使用 Ubuntu 官方镜像
Ubuntu 相关的镜像有很多这里使用 `-s 10` 参数只搜索那些被收藏 10 次以上的镜像
Ubuntu 相关的镜像有很多这里使用 `--filter=stars=10` 参数只搜索那些被收藏 10 次以上的镜像
```bash
$ docker search -s 10 ubuntu
$ docker search --filter=stars=10 ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Official Ubuntu base image 840 [OK]
@@ -56,27 +56,32 @@ crashsystems/gitlab-docker A trusted, regularly updated build of GitL.
sylvainlasnier/memcached This is a Memcached 1.4.14 docker images b... 16 [OK]
ubuntu-upstart Upstart is an event-based replacement for ... 16 [OK]
mbentley/ubuntu-django-uwsgi-nginx 16 [OK]
ansible/ubuntu14.04-ansible Ubuntu 14.04 LTS with ansible 15 [OK]
clue/ttrss The Tiny Tiny RSS feed reader allows you t... 14 [OK]
dockerfile/ubuntu-desktop Trusted automated Ubuntu Desktop (LXDE) (h... 14 [OK]
tutum/ubuntu Ubuntu image with SSH access. For the root... 12 [OK]
```
*注意Docker 1.12 版本中已经不支持 --stars 参数则可以使用 -f stars=N 参数*
根据搜索出来的结果读者可以自行选择下载镜像并使用
下面以 ubuntu 14.04 为例演示如何使用该镜像安装一些常用软件
下面以 ubuntu 18.04 为例演示如何使用该镜像安装一些常用软件
首先使用 `-ti` 参数启动容器登录 bash查看 ubuntu 的发行版本号
```bash
$ docker run -ti ubuntu:14.04 /bin/bash
root@7d93de07bf76:/# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Codename: trusty
$ docker run -ti ubuntu:18.04 /bin/bash
root@7d93de07bf76:/# cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.1 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
```
当试图直接使用 `apt-get` 安装一个软件的时候会提示 `E: Unable to locate package`

View File

@@ -2,9 +2,10 @@
![阿里云](_images/aliyun-logo.png)
阿里云创立于 2009 是中国较早的云计算平台阿里云致力于提供安全可靠的计算和数据处理能力
[阿里云](https://www.aliyun.com?source=5176.11533457&userCode=8lx5zmtu&type=copy) 创立于 2009 年,是中国较早的云计算平台阿里云致力于提供安全可靠的计算和数据处理能力。
阿里云的客户群体中活跃着微博知乎魅族锤子科技小咖秀等一大批明星互联网公司在天猫双 11 全球狂欢节等极富挑战的应用场景中阿里云保持着良好的运行纪录
[阿里云](https://www.aliyun.com?source=5176.11533457&userCode=8lx5zmtu&type=copy) 的客户群体中,活跃着微博、知乎、魅族、锤子科技、小咖秀等一大批明星互联网公司。在天猫双 11 全球狂欢节等极富挑战的应用场景中阿里云保持着良好的运行纪录。
阿里云容器服务提供了高性能可伸缩的容器应用管理服务支持在一组云服务器上通过 Docker 容器来进行应用生命周期管理容器服务极大简化了用户对容器管理集群的搭建工作无缝整合了阿里云虚拟化存储网络和安全能力容器服务提供了多种应用发布方式和流水线般的持续交付能力原生支持微服务架构助力用户无缝上云和跨云管理
[阿里云容器服务 Kubernetes ACK](https://www.aliyun.com/product/kubernetes?source=5176.11533457&userCode=8lx5zmtu&type=copy) 提供了高性能可伸缩的容器应用管理服务支持在一组云服务器上通过 Docker 容器来进行应用生命周期管理容器服务极大简化了用户对容器管理集群的搭建工作无缝整合了阿里云虚拟化、存储、网络和安全能力容器服务提供了多种应用发布方式和流水线般的持续交付能力原生支持微服务架构助力用户无缝上云和跨云管理。
![](https://img.alicdn.com/tps/TB10yjtPpXXXXacXXXXXXXXXXXX-1531-1140.png)

View File

@@ -2,12 +2,10 @@
![AWS](_images/aws-logo.jpg)
AWS Amazon Web Services是亚马逊Amazon公司的 IaaS PaaS 平台服务AWS 提供了一整套基础设施和应用程序服务使用户几乎能够在云中运行一切应用程序从企业应用程序和大数据项目到社交游戏和移动应用程序AWS 面向用户提供包括弹性计算存储数据库应用程序在内的一整套云计算服务能够帮助企业降低 IT 投入成本和维护成本
[AWS](https://www.amazonaws.cn),即 Amazon Web Services是亚马逊Amazon公司的 IaaS 和 PaaS 平台服务。AWS 提供了一整套基础设施和应用程序服务使用户几乎能够在云中运行一切应用程序从企业应用程序和大数据项目到社交游戏和移动应用程序。AWS 面向用户提供包括弹性计算、存储、数据库、应用程序在内的一整套云计算服务能够帮助企业降低 IT 投入成本和维护成本。
2006 年初起亚马逊 AWS 开始在云中为各种规模的公司提供技术服务平台利用亚马逊 AWS软件开发人员可以轻松购买计算存储数据库和其他基于 Internet 的服务来支持其应用程序开发人员能够灵活选择任何开发平台或编程环境以便于其尝试解决问题由于开发人员只需按使用量付费无需前期资本支出亚马逊 AWS 是向最终用户交付计算资源保存的数据和其他应用程序的一种经济划算的方式
2015 AWS 正式发布了 EC2 容器服务(ECS)ECS 的目的是让 Docker 容器变的更加简单它提供了一个集群和编排的层用来控制主机上的容器部署以及部署之后的集群内的容器的生命周期管理ECS 是诸如 Docker SwarmKubernetesMesos 等工具的替代它们工作在同一个层除了作为一个服务来提供这些工具和 ECS 不同的地方在于前者需要用户自己来部署和管理 ECS 作为服务来提供的
![AWS 容器服务](_images/ECS.jpg)

View File

@@ -1,9 +0,0 @@
## 腾讯云
![腾讯云](_images/qcloud-logo.jpg)
腾讯云在架构方面经过多年积累并且有着多年对海量互联网服务的经验不管是社交游戏还是其他领域都有多年的成熟产品来提供产品服务腾讯在云端完成重要部署为开发者及企业提供云服务云数据云运营等整体一站式服务方案
具体包括云服务器云存储云数据库和弹性 web 引擎等基础云服务腾讯云分析MTA腾讯云推送信鸽等腾讯整体大数据能力以及 QQ互联QQ 空间微云微社区等云端链接社交体系这些正是腾讯云可以提供给这个行业的差异化优势造就了可支持各种互联网使用场景的高品质的腾讯云技术平台
腾讯云容器服务是高度可扩展的高性能容器管理服务用户可以在托管的云服务器实例集群上轻松运行应用程序使用该服务将无需安装运维扩展用户的集群管理基础设施只需进行简单的API调用便可启动和停止Docker应用程序查询集群的完整状态以及使用各种云服务用户可以根据用户的资源需求和可用性要求在用户的集群中安排容器的置放满足业务或应用程序的特定要求

View File

@@ -1,4 +1,5 @@
## 本章小结
本章介绍了公有云服务对 Docker 的积极支持以及新出现的容器云平台
事实上Docker 技术的出现自身就极大推动了云计算行业的发展

11
cloud/tencentCloud.md Normal file
View File

@@ -0,0 +1,11 @@
## 腾讯云
![腾讯云](_images/qcloud-logo.jpg)
[腾讯云](https://cloud.tencent.com/redirect.php?redirect=1040&cps_key=3a5255852d5db99dcd5da4c72f05df61&from=console) 在架构方面经过多年积累,并且有着多年对海量互联网服务的经验。不管是社交、游戏还是其他领域,都有多年的成熟产品来提供产品服务。腾讯在云端完成重要部署,为开发者及企业提供云服务、云数据、云运营等整体一站式服务方案。
具体包括 [云服务器](https://cloud.tencent.com/redirect.php?redirect=1001&cps_key=3a5255852d5db99dcd5da4c72f05df61&from=console)、[云存储](https://cloud.tencent.com/redirect.php?redirect=1020&cps_key=3a5255852d5db99dcd5da4c72f05df61&from=console)、[云数据库](https://cloud.tencent.com/redirect.php?redirect=1003&cps_key=3a5255852d5db99dcd5da4c72f05df61&from=console)、[视频与CDN](https://cloud.tencent.com/redirect.php?redirect=1019&cps_key=3a5255852d5db99dcd5da4c72f05df61&from=console) 和 [域名注册](https://dnspod.cloud.tencent.com) 等基础云服务腾讯云分析MTA、腾讯云推送信鸽等腾讯整体大数据能力以及 QQ互联、QQ 空间、微云、微社区等云端链接社交体系。这些正是腾讯云可以提供给这个行业的差异化优势,造就了可支持各种互联网使用场景的高品质的腾讯云技术平台。
[腾讯云容器服务 TKE](https://cloud.tencent.com/redirect.php?redirect=10058&cps_key=3a5255852d5db99dcd5da4c72f05df61) 是高度可扩展的高性能容器管理服务,用户可以在托管的云服务器实例集群上轻松运行应用程序。使用该服务,将无需安装、运维、扩展用户的集群管理基础设施,只需进行简单的 API 调用,便可启动和停止 Docker 应用程序,查询集群的完整状态,以及使用各种云服务。用户可以根据用户的资源需求和可用性要求在用户的集群中安排容器的置放,满足业务或应用程序的特定要求。
![](https://mc.qcloudimg.com/static/img/0581dbeb97c869bbe6e62025dbc592d7/image.png)

View File

@@ -1,5 +1,5 @@
# Docker Compose 项目
`Docker Compose` Docker 官方编排Orchestration项目之一负责快速在集群中部署分布式应用
`Docker Compose` Docker 官方编排Orchestration项目之一负责快速部署分布式应用
本章将介绍 `Compose` 项目情况以及安装和使用

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -1,6 +1,7 @@
## Compose 命令说明
### 命令对象与格式
对于 Compose 来说大部分命令的对象既可以是项目本身也可以指定为项目中的服务或者容器如果没有特别的说明命令对象将是项目这意味着项目中所有的服务都会受到命令影响
执行 `docker-compose [COMMAND] --help` 或者 `docker-compose help [COMMAND]` 可以查看具体某个命令的使用格式
@@ -66,6 +67,7 @@ docker-compose [-f=<arg>...] [options] [COMMAND] [ARGS...]
列出 Compose 文件中包含的镜像
#### `kill`
格式为 `docker-compose kill [options] [SERVICE...]`
通过发送 `SIGKILL` 信号来强制停止服务容器
@@ -77,6 +79,7 @@ $ docker-compose kill -s SIGINT
```
#### `logs`
格式为 `docker-compose logs [options] [SERVICE...]`
查看服务容器的输出默认情况下docker-compose 将对不同的服务输出使用不同的颜色来区分可以通过 `--no-color` 来关闭颜色
@@ -84,11 +87,13 @@ $ docker-compose kill -s SIGINT
该命令在调试问题的时候十分有用
#### `pause`
格式为 `docker-compose pause [SERVICE...]`
暂停一个服务容器
#### `port`
格式为 `docker-compose port [options] SERVICE PRIVATE_PORT`
打印某个容器端口所映射的公共端口
@@ -100,6 +105,7 @@ $ docker-compose kill -s SIGINT
* `--index=index` 如果同一服务存在多个容器指定命令对象容器的序号默认为 1
#### `ps`
格式为 `docker-compose ps [options] [SERVICE...]`
列出项目中目前的所有容器
@@ -109,6 +115,7 @@ $ docker-compose kill -s SIGINT
* `-q` 只打印容器的 ID 信息
#### `pull`
格式为 `docker-compose pull [options] [SERVICE...]`
拉取服务依赖的镜像
@@ -122,6 +129,7 @@ $ docker-compose kill -s SIGINT
推送服务依赖的镜像到 Docker 镜像仓库
#### `restart`
格式为 `docker-compose restart [options] [SERVICE...]`
重启项目中的服务
@@ -131,6 +139,7 @@ $ docker-compose kill -s SIGINT
* `-t, --timeout TIMEOUT` 指定重启前停止容器的超时默认为 10
#### `rm`
格式为 `docker-compose rm [options] [SERVICE...]`
删除所有停止状态的服务容器推荐先执行 `docker-compose stop` 命令来停止容器
@@ -195,6 +204,7 @@ $ docker-compose run --no-deps web python manage.py shell
* `-T` 不分配伪 tty意味着依赖 tty 的指令将无法运行
#### `scale`
格式为 `docker-compose scale [options] [SERVICE=NUM...]`
设置指定服务运行的容器个数
@@ -214,11 +224,13 @@ $ docker-compose scale web=3 db=2
* `-t, --timeout TIMEOUT` 停止容器时候的超时默认为 10
#### `start`
格式为 `docker-compose start [SERVICE...]`
启动已经存在的服务容器
#### `stop`
格式为 `docker-compose stop [options] [SERVICE...]`
停止已经处于运行状态的容器但不删除它通过 `docker-compose start` 可以再次启动这些容器
@@ -232,11 +244,13 @@ $ docker-compose scale web=3 db=2
查看各个服务容器内运行的进程
#### `unpause`
格式为 `docker-compose unpause [SERVICE...]`
恢复处于暂停状态中的服务
#### `up`
格式为 `docker-compose up [options] [SERVICE...]`
该命令十分强大它将尝试自动完成包括构建镜像重新创建服务启动服务并关联服务相关容器的一系列操作
@@ -270,6 +284,11 @@ $ docker-compose scale web=3 db=2
* `-t, --timeout TIMEOUT` 停止容器时候的超时默认为 10
#### `version`
格式为 `docker-compose version`
打印版本信息
### 参考资料
* [官方文档](https://docs.docker.com/compose/reference/overview/)

View File

@@ -18,7 +18,7 @@ services:
注意每个服务都必须通过 `image` 指令指定镜像或 `build` 指令需要 Dockerfile等来自动构建生成镜像
如果使用 `build` 指令 `Dockerfile` 中设置的选项(例如`CMD`, `EXPOSE`, `VOLUME`, `ENV` ) 将会自动被获取无需在 `docker-compose.yml` 再次设置
如果使用 `build` 指令 `Dockerfile` 中设置的选项(例如`CMD`, `EXPOSE`, `VOLUME`, `ENV` ) 将会自动被获取无需在 `docker-compose.yml` 重复设置
下面分别介绍各个指令的用法
@@ -27,7 +27,39 @@ services:
指定 `Dockerfile` 所在文件夹的路径可以是绝对路径或者相对 docker-compose.yml 文件的路径 `Compose` 将会利用它自动构建这个镜像然后使用这个镜像
```yaml
build: /path/to/build/dir
version: '3'
services:
webapp:
build: ./dir
```
你也可以使用 `context` 指令指定 `Dockerfile` 所在文件夹的路径
使用 `dockerfile` 指令指定 `Dockerfile` 文件名
使用 `arg` 指令指定构建镜像时的变量
```yaml
version: '3'
services:
webapp:
build:
context: ./dir
dockerfile: Dockerfile-alternate
args:
buildno: 1
```
使用 `cache_from` 指定构建镜像的缓存
```yaml
build:
context: .
cache_from:
- alpine:latest
- corp/web_app:3.14
```
### `cap_add, cap_drop`
@@ -78,7 +110,7 @@ cgroup_parent: cgroups_1
container_name: docker-web-container
```
需要注意指定容器名称后该服务将无法进行扩展scale因为 Docker 不允许多个容器具有相同的名称
>注意: 指定容器名称后该服务将无法进行扩展scale因为 Docker 不允许多个容器具有相同的名称
### `deploy`
@@ -114,6 +146,8 @@ services:
image: postgres
```
>注意`web` 服务不会等待 `redis` `db` 完全启动之后才启动
### `dns`
自定义 `DNS` 服务器可以是一个值也可以是一个列表
@@ -189,9 +223,7 @@ environment:
- SESSION_SECRET
```
注意如果变量名称或者值中用到 `true|falseyes|no` 等表达布尔含义的词汇最好放到引号里避免 YAML 自动解析某些内容为对应的布尔语义
`http://yaml.org/type/bool.html` 中给出了这些特定词汇包括
如果变量名称或者值中用到 `true|falseyes|no` 等表达 [布尔](https://yaml.org/type/bool.html) 含义的词汇,最好放到引号里,避免 YAML 自动解析某些内容为对应的布尔语义。这些特定词汇,包括
```bash
y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF
@@ -211,7 +243,9 @@ expose:
### `external_links`
链接到 docker-compose.yml 外部的容器甚至并非 `Compose` 管理的外部容器参数格式跟 `links` 类似
>注意不建议使用该指令
链接到 `docker-compose.yml` 外部的容器甚至并非 `Compose` 管理的外部容器
```yaml
external_links:
@@ -251,7 +285,7 @@ healthcheck:
### `image`
指定为镜像名称或镜像 ID如果镜像在本地不存在`Compose` 将会尝试拉这个镜像
指定为镜像名称或镜像 ID如果镜像在本地不存在`Compose` 将会尝试拉这个镜像
```yaml
image: ubuntu
@@ -272,7 +306,7 @@ labels:
### `links`
不推荐使用该指令
>注意不推荐使用该指令
### `logging`
@@ -303,7 +337,7 @@ options:
### `network_mode`
设置网络模式使用和 `docker run` `--net` 参数一样的值
设置网络模式使用和 `docker run` `--network` 参数一样的值
```yaml
network_mode: "bridge"
@@ -343,7 +377,7 @@ pid: "host"
暴露端口信息
使用宿主容器 `HOST:CONTAINER`格式或者仅仅指定容器的端口宿主将会随机选择端口都可以
使用宿主端口容器端口 `(HOST:CONTAINER)` 格式或者仅仅指定容器的端口宿主将会随机选择端口都可以
```yaml
ports:
@@ -357,7 +391,26 @@ ports:
### `secrets`
仅用于 `Swarm mode`详细内容请查看 [`Swarm mode`](../swarm_mode/) 一节
存储敏感数据例如 `mysql` 服务密码
```yaml
version: "3.1"
services:
mysql:
image: mysql
environment:
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password
secrets:
- db_root_password
- my_other_secret
secrets:
my_secret:
file: ./my_secret.txt
my_other_secret:
external: true
```
### `security_opt`
@@ -407,7 +460,7 @@ sysctls:
### `volumes`
数据卷所挂载路径设置可以设置宿主机路径 `HOST:CONTAINER` 或加上访问模式 `HOST:CONTAINER:ro`
数据卷所挂载路径设置可以设置宿主机路径(`HOST:CONTAINER`)或者数据卷名称(`VOLUME:CONTAINER`)并且可以设置访问模式 `HOST:CONTAINER:ro`
该指令中路径支持相对路径
@@ -418,6 +471,21 @@ volumes:
- ~/configs:/etc/configs/:ro
```
如果路径为数据卷名称必须在文件中配置数据卷
```yaml
version: "3"
services:
my_src:
image: mysql:8.0
volumes:
- mysql_data:/var/lib/mysql
volumes:
mysql_data:
```
### 其它指令
此外还有包括 `domainname, entrypoint, hostname, ipc, mac_address, privileged, read_only, shm_size, restart, stdin_open, tty, user, working_dir` 等指令基本跟 `docker run` 中对应参数的功能一致
@@ -448,12 +516,6 @@ hostname: test
mac_address: 08-00-27-00-0C-0A
```
指定容器中
```yaml
ipc: host
```
允许容器中运行一些特权命令
```yaml
@@ -478,21 +540,39 @@ read_only: true
stdin_open: true
```
模拟一个假的远程控制台
模拟一个伪终端
```yaml
tty: true
```
### 读取环境变量
### 读取变量
Compose 模板文件支持动态读取主机的系统环境变量
Compose 模板文件支持动态读取主机的系统环境变量和当前目录下的 `.env` 文件中的变量
例如下面的 Compose 文件将从运行它的环境中读取变量 ${MONGO_VERSION} 的值并写入执行的指令中
例如下面的 Compose 文件将从运行它的环境中读取变量 `${MONGO_VERSION}` 的值并写入执行的指令中
```yaml
version: "3"
services:
db:
image: "mongo:${MONGO_VERSION}"
```
如果执行 `MONGO_VERSION=3.2 docker-compose up` 则会启动一个 `mongo:3.2` 镜像的容器如果执行 `MONGO_VERSION=2.8 docker-compose up` 则会启动一个 `mongo:2.8` 镜像的容器
若当前目录存在 `.env` 文件执行 `docker-compose` 命令时将从该文件中读取变量
在当前目录新建 `.env` 文件并写入以下内容
```bash
# 支持 # 号注释
MONGO_VERSION=3.6
```
执行 `docker-compose up` 则会启动一个 `mongo:3.6` 镜像的容器
### 参考资料
* [官方文档](https://docs.docker.com/compose/compose-file/)

View File

@@ -0,0 +1,5 @@
FROM python:3.6-alpine
ADD . /code
WORKDIR /code
RUN pip install redis flask
CMD ["python", "app.py"]

13
compose/demo/app/app.py Normal file
View File

@@ -0,0 +1,13 @@
from flask import Flask
from redis import Redis
app = Flask(__name__)
redis = Redis(host='redis', port=6379)
@app.route('/')
def hello():
count = redis.incr('hits')
return 'Hello World! 该页面已被访问 {} \n'.format(count)
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)

View File

@@ -0,0 +1,10 @@
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
redis:
image: "redis:alpine"

View File

@@ -1,29 +0,0 @@
version: "3"
services:
weba:
build: ./web
expose:
- 80
webb:
build: ./web
expose:
- 80
webc:
build: ./web
expose:
- 80
haproxy:
image: haproxy:latest
volumes:
- ./haproxy:/haproxy-override
- ./haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
ports:
- "80:80"
- "70:70"
expose:
- "80"
- "70"

View File

@@ -1,32 +0,0 @@
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
listen stats
bind 0.0.0.0:70
stats enable
stats uri /
frontend balancer
bind 0.0.0.0:80
mode http
default_backend web_backends
backend web_backends
mode http
option forwardfor
balance roundrobin
server weba weba:80 check
server webb webb:80 check
server webc webc:80 check
option httpchk GET /
http-check expect status 200

View File

@@ -1,5 +0,0 @@
FROM python:2.7
WORKDIR /code
ADD . /code
EXPOSE 80
CMD python index.py

View File

@@ -1,68 +0,0 @@
#!/usr/bin/python
#authors: yeasy.github.com
#date: 2013-07-05
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
import socket
import fcntl
import struct
import pickle
from datetime import datetime
from collections import OrderedDict
class HandlerClass(SimpleHTTPRequestHandler):
def get_ip_address(self,ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
def log_message(self, format, *args):
if len(args) < 3 or "200" not in args[1]:
return
try:
request = pickle.load(open("pickle_data.txt","r"))
except:
request=OrderedDict()
time_now = datetime.now()
ts = time_now.strftime('%Y-%m-%d %H:%M:%S')
server = self.get_ip_address('eth0')
host=self.address_string()
addr_pair = (host,server)
if addr_pair not in request:
request[addr_pair]=[1,ts]
else:
num = request[addr_pair][0]+1
del request[addr_pair]
request[addr_pair]=[num,ts]
file=open("index.html", "w")
file.write("<!DOCTYPE html> <html> <body><center><h1><font color=\"blue\" face=\"Georgia, Arial\" size=8><em>HA</em></font> Webpage Visit Results</h1></center>")
for pair in request:
if pair[0] == host:
guest = "LOCAL: "+pair[0]
else:
guest = pair[0]
if (time_now-datetime.strptime(request[pair][1],'%Y-%m-%d %H:%M:%S')).seconds < 3:
file.write("<p style=\"font-size:150%\" >#"+ str(request[pair][1]) +": <font color=\"red\">"+str(request[pair][0])+ "</font> requests " + "from &lt<font color=\"blue\">"+guest+"</font>&gt to WebServer &lt<font color=\"blue\">"+pair[1]+"</font>&gt</p>")
else:
file.write("<p style=\"font-size:150%\" >#"+ str(request[pair][1]) +": <font color=\"maroon\">"+str(request[pair][0])+ "</font> requests " + "from &lt<font color=\"navy\">"+guest+"</font>&gt to WebServer &lt<font color=\"navy\">"+pair[1]+"</font>&gt</p>")
file.write("</body> </html>")
file.close()
pickle.dump(request,open("pickle_data.txt","w"))
if __name__ == '__main__':
try:
ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.0"
addr = len(sys.argv) < 2 and "0.0.0.0" or sys.argv[1]
port = len(sys.argv) < 3 and 80 or int(sys.argv[2])
HandlerClass.protocol_version = Protocol
httpd = ServerClass((addr, port), HandlerClass)
sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1], "..."
httpd.serve_forever()
except:
exit()

View File

@@ -1 +1,2 @@
django_example
manage.py

View File

@@ -6,7 +6,7 @@ services:
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:

View File

@@ -1,22 +0,0 @@
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_example.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)

View File

@@ -1,2 +1,2 @@
Django>=1.8,<2.0
psycopg2
Django>=2.0,<3.0
psycopg2>=2.7,<3.0

View File

@@ -2,7 +2,11 @@ version: "3"
services:
db:
image: mysql:5.7
image: mysql:8.0
command:
- --default_authentication_plugin=mysql_native_password
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
volumes:
- db_data:/var/lib/mysql
restart: always
@@ -24,4 +28,4 @@ services:
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
db_data:

View File

@@ -1,6 +1,6 @@
## 使用 Django
本小节内容适合 `Python` 开发人员阅读
> 本小节内容适合 `Python` 开发人员阅读
我们现在将使用 `Docker Compose` 配置并运行一个 `Django/PostgreSQL` 应用
@@ -8,23 +8,23 @@
第一步因为应用将要运行在一个满足所有环境依赖的 Docker 容器里面那么我们可以通过编辑 `Dockerfile` 文件来指定 Docker 容器要安装内容内容如下
```docker
```dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
COPY requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
COPY . /code/
```
以上内容指定应用将使用安装了 Python 以及必要依赖包的镜像更多关于如何编写 `Dockerfile` 文件的信息可以查看 [镜像创建](../image/create.md#利用 Dockerfile 来创建镜像) [ Dockerfile 使用](../dockerfile/README.md)
以上内容指定应用将使用安装了 Python 以及必要依赖包的镜像更多关于如何编写 `Dockerfile` 文件的信息可以查看 [ Dockerfile 使用](../image/dockerfile/README.md)
第二步 `requirements.txt` 文件里面写明需要安装的具体依赖包名
```bash
Django>=1.8,<2.0
psycopg2
Django>=2.0,<3.0
psycopg2>=2.7,<3.0
```
第三步`docker-compose.yml` 文件将把所有的东西关联起来它描述了应用的构成一个 web 服务和一个数据库使用的 Docker 镜像镜像之间的连接挂载到容器的卷以及服务开放的端口
@@ -38,7 +38,7 @@ services:
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
@@ -47,15 +47,15 @@ services:
- db
```
查看 [`docker-compose.yml` 章节](yml_ref.md) 了解更多详细的工作机制
查看 [`docker-compose.yml` 章节](compose_file.md) 了解更多详细的工作机制
现在我们就可以使用 `docker-compose run` 命令启动一个 `Django` 应用了
```bash
$ docker-compose run web django-admin.py startproject django_example .
$ docker-compose run web django-admin startproject django_example .
```
Compose 会先使用 `Dockerfile` web 服务建一个镜像接着使用这个镜像在容器里运行 `django-admin.py startproject composeexample` 指令
由于 web 服务所使用的镜像并不存在所以 Compose 先使用 `Dockerfile` web 服务建一个镜像接着使用这个镜像在容器里运行 `django-admin startproject django_example` 指令
这将在当前目录生成一个 `Django` 应用
@@ -67,7 +67,7 @@ Dockerfile docker-compose.yml django_example manage.py
如果你的系统是 Linux,记得更改文件权限
```bash
sudo chown -R $USER:$USER .
$ sudo chown -R $USER:$USER .
```
首先我们要为应用设置好数据库的连接信息用以下内容替换 `django_example/settings.py` 文件中 `DATABASES = ...` 定义的节点内容
@@ -84,7 +84,7 @@ DATABASES = {
}
```
这些信息是在 [postgres](https://store.docker.com/images/postgres/) 镜像固定设置好的。然后,运行 `docker-compose up`
这些信息是在 [postgres](https://hub.docker.com/_/postgres/) 镜像固定设置好的。然后,运行 `docker-compose up`
```bash
$ docker-compose up

View File

@@ -4,14 +4,12 @@
`Compose` 可以通过 Python 的包管理工具 `pip` 进行安装也可以直接下载编译好的二进制文件使用甚至能够直接在 Docker 容器中运行
前两种方式是传统方式适合本地环境下安装使用最后一种方式则不破坏系统环境更适合云计算场景
`Docker for Mac` `Docker for Windows` 自带 `docker-compose` 二进制文件安装 Docker 之后可以直接使用
`Docker Desktop for Mac/Windows` 自带 `docker-compose` 二进制文件安装 Docker 之后可以直接使用
```bash
$ docker-compose --version
docker-compose version 1.17.1, build 6d101fb
docker-compose version 1.24.1, build 4667896b
```
Linux 系统请使用以下介绍的方法安装
@@ -23,7 +21,8 @@ Linux 系统请使用以下介绍的方法安装。
例如 Linux 64 位系统上直接下载对应的二进制包
```bash
$ sudo curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
$ sudo curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
```
@@ -43,7 +42,7 @@ $ sudo pip install -U docker-compose
```bash
Collecting docker-compose
Downloading docker-compose-1.17.1.tar.gz (149kB): 149kB downloaded
Downloading docker-compose-1.24.1.tar.gz (149kB): 149kB downloaded
...
Successfully installed docker-compose cached-property requests texttable websocket-client docker-py dockerpty six enum34 backports.ssl-match-hostname ipaddress
```
@@ -51,66 +50,9 @@ Successfully installed docker-compose cached-property requests texttable websock
### bash 补全命令
```bash
$ curl -L https://raw.githubusercontent.com/docker/compose/1.8.0/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose
$ curl -L https://raw.githubusercontent.com/docker/compose/1.24.1/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose
```
### 容器中执行
Compose 既然是一个 Python 应用自然也可以直接用容器来执行它
```bash
$ curl -L https://github.com/docker/compose/releases/download/1.8.0/run.sh > /usr/local/bin/docker-compose
$ chmod +x /usr/local/bin/docker-compose
```
实际上查看下载的 `run.sh` 脚本内容如下
```bash
set -e
VERSION="1.8.0"
IMAGE="docker/compose:$VERSION"
# Setup options for connecting to docker host
if [ -z "$DOCKER_HOST" ]; then
DOCKER_HOST="/var/run/docker.sock"
fi
if [ -S "$DOCKER_HOST" ]; then
DOCKER_ADDR="-v $DOCKER_HOST:$DOCKER_HOST -e DOCKER_HOST"
else
DOCKER_ADDR="-e DOCKER_HOST -e DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH"
fi
# Setup volume mounts for compose config and context
if [ "$(pwd)" != '/' ]; then
VOLUMES="-v $(pwd):$(pwd)"
fi
if [ -n "$COMPOSE_FILE" ]; then
compose_dir=$(dirname $COMPOSE_FILE)
fi
# TODO: also check --file argument
if [ -n "$compose_dir" ]; then
VOLUMES="$VOLUMES -v $compose_dir:$compose_dir"
fi
if [ -n "$HOME" ]; then
VOLUMES="$VOLUMES -v $HOME:$HOME -v $HOME:/root" # mount $HOME in /root to share docker.config
fi
# Only allocate tty if we detect one
if [ -t 1 ]; then
DOCKER_RUN_OPTIONS="-t"
fi
if [ -t 0 ]; then
DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -i"
fi
exec docker run --rm $DOCKER_RUN_OPTIONS $DOCKER_ADDR $COMPOSE_OPTIONS $VOLUMES -w "$(pwd)" $IMAGE "$@"
```
可以看到它其实是下载了 `docker/compose` 镜像并运行
### 卸载
如果是二进制包方式安装的删除二进制文件即可

View File

@@ -1,7 +1,5 @@
## Compose 简介
![Docker Compose 项目](_images/docker_compose.jpg)
`Compose` 项目是 Docker 官方的开源项目负责实现对 Docker 容器集群的快速编排从功能上看 `OpenStack` 中的 `Heat` 十分类似
其代码目前在 [https://github.com/docker/compose](https://github.com/docker/compose) 上开源。

View File

@@ -1,6 +1,6 @@
## 使用 Rail
## 使用 Rails
本小节内容适合 `Ruby` 开发人员阅读
> 本小节内容适合 `Ruby` 开发人员阅读
我们现在将使用 `Compose` 配置并运行一个 `Rails/PostgreSQL` 应用
@@ -8,7 +8,7 @@
首先因为应用将要运行在一个满足所有环境依赖的 Docker 容器里面那么我们可以通过编辑 `Dockerfile` 文件来指定 Docker 容器要安装内容内容如下
```docker
```dockerfile
FROM ruby
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
RUN mkdir /myapp
@@ -17,13 +17,16 @@ ADD Gemfile /myapp/Gemfile
RUN bundle install
ADD . /myapp
```
以上内容指定应用将使用安装了 RubyBundler 以及其依赖件的镜像更多关于如何编写 Dockerfile 文件的信息可以查看 [镜像创建](../image/create.md#利用 Dockerfile 来创建镜像) [Dockerfile 使用](../dockerfile/README.md)
以上内容指定应用将使用安装了 RubyBundler 以及其依赖件的镜像更多关于如何编写 Dockerfile 文件的信息可以查看 [Dockerfile 使用](../image/dockerfile/README.md)
下一步我们需要一个引导加载 Rails 的文件 `Gemfile` 等一会儿它还会被 `rails new` 命令覆盖重写
```bash
source 'https://rubygems.org'
gem 'rails', '4.0.2'
```
最后`docker-compose.yml` 文件才是最神奇的地方 `docker-compose.yml` 文件将把所有的东西关联起来它描述了应用的构成一个 web 服务和一个数据库每个镜像的来源数据库运行在使用预定义的 PostgreSQL 镜像web 应用侧将从本地目录创建镜像之间的连接以及服务开放的端口
```yaml
@@ -45,11 +48,13 @@ services:
links:
- db
```
所有文件就绪后我们就可以通过使用 `docker-compose run` 命令生成应用的骨架了
```bash
$ docker-compose run web rails new . --force --database=postgresql --skip-bundle
```
`Compose` 会先使用 `Dockerfile` web 服务创建一个镜像接着使用这个镜像在容器里运行 `rails new ` 和它之后的命令一旦这个命令运行完后应该就可以看一个崭新的应用已经生成了
```bash
@@ -60,16 +65,19 @@ Gemfile.lock condocker-compose log
README.rdoc condocker-compose.ru public
Rakefile db test
```
在新的 `Gemfile` 文件去掉加载 `therubyracer` 的行的注释这样我们便可以使用 Javascript 运行环境
```bash
gem 'therubyracer', platforms: :ruby
```
现在我们已经有一个新的 `Gemfile` 文件需要再重新创建镜像这个会步骤会改变 Dockerfile 文件本身仅仅需要重建一次
现在我们已经有一个新的 `Gemfile` 文件需要再重新创建镜像这个会步骤会改变 Dockerfile 文件本身所以需要重建一次
```bash
$ docker-compose build
```
应用现在就可以启动了但配置还未完成Rails 默认读取的数据库目标是 `localhost` 我们需要手动指定容器的 `db` 同样的还需要把用户名修改成和 postgres 镜像预定的一致
打开最新生成的 `database.yml` 文件用以下内容替换
@@ -87,11 +95,13 @@ test:
<<: *default
database: myapp_test
```
现在就可以启动应用了
```bash
$ docker-compose up
```
如果一切正常你应该可以看到 PostgreSQL 的输出几秒后可以看到这样的重复信息
```bash
@@ -99,11 +109,13 @@ myapp_web_1 | [2014-01-17 17:16:29] INFO WEBrick 1.3.1
myapp_web_1 | [2014-01-17 17:16:29] INFO ruby 2.0.0 (2013-11-22) [x86_64-linux-gnu]
myapp_web_1 | [2014-01-17 17:16:29] INFO WEBrick::HTTPServer#start: pid=1 port=3000
```
最后 我们需要做的是创建数据库打开另一个终端运行
```bash
$ docker-compose run web rake db:create
```
这个 web 应用已经开始在你的 docker 守护进程里面监听着 3000 端口了
![](../_images/docker-compose-rails-screenshot.png)

View File

@@ -1,6 +1,7 @@
## 使用
### 术语
首先介绍几个术语
* 服务 (`service`)一个应用容器实际上可以运行多个相同镜像的实例
@@ -10,197 +11,64 @@
可见一个项目可以由多个服务容器关联而成`Compose` 面向项目进行管理
### 场景
下面我们创建一个经典的 Web 项目一个 [Haproxy](http://www.haproxy.org/),挂载三个 Web 容器。
创建一个 `compose-haproxy-web` 目录作为项目工作目录并在其中分别创建两个子目录`haproxy` `web`
最常见的项目是 web 网站该项目应该包含 web 应用和缓存
### web 子目录
下面我们用 `Python` 来建立一个能够记录页面访问次数的 web 网站
这里用 Python 程序来提供一个简单的 HTTP 服务打印出访问者的 IP 实际的本地 IP
#### web 应用
#### index.py
新建文件夹在该目录中编写 `app.py` 文件
编写一个 `index.py` 作为服务器文件代码为
```python
#!/usr/bin/python
#authors: yeasy.github.com
#date: 2013-07-05
from flask import Flask
from redis import Redis
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
import socket
import fcntl
import struct
import pickle
from datetime import datetime
from collections import OrderedDict
app = Flask(__name__)
redis = Redis(host='redis', port=6379)
class HandlerClass(SimpleHTTPRequestHandler):
def get_ip_address(self,ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
def log_message(self, format, *args):
if len(args) < 3 or "200" not in args[1]:
return
try:
request = pickle.load(open("pickle_data.txt","r"))
except:
request=OrderedDict()
time_now = datetime.now()
ts = time_now.strftime('%Y-%m-%d %H:%M:%S')
server = self.get_ip_address('eth0')
host=self.address_string()
addr_pair = (host,server)
if addr_pair not in request:
request[addr_pair]=[1,ts]
else:
num = request[addr_pair][0]+1
del request[addr_pair]
request[addr_pair]=[num,ts]
file=open("index.html", "w")
file.write("<!DOCTYPE html> <html> <body><center><h1><font color=\"blue\" face=\"Georgia, Arial\" size=8><em>HA</em></font> Webpage Visit Results</h1></center>")
for pair in request:
if pair[0] == host:
guest = "LOCAL: "+pair[0]
else:
guest = pair[0]
if (time_now-datetime.strptime(request[pair][1],'%Y-%m-%d %H:%M:%S')).seconds < 3:
file.write("<p style=\"font-size:150%\" >#"+ str(request[pair][1]) +": <font color=\"red\">"+str(request[pair][0])+ "</font> requests " + "from &lt<font color=\"blue\">"+guest+"</font>&gt to WebServer &lt<font color=\"blue\">"+pair[1]+"</font>&gt</p>")
else:
file.write("<p style=\"font-size:150%\" >#"+ str(request[pair][1]) +": <font color=\"maroon\">"+str(request[pair][0])+ "</font> requests " + "from &lt<font color=\"navy\">"+guest+"</font>&gt to WebServer &lt<font color=\"navy\">"+pair[1]+"</font>&gt</p>")
file.write("</body> </html>")
file.close()
pickle.dump(request,open("pickle_data.txt","w"))
@app.route('/')
def hello():
count = redis.incr('hits')
return 'Hello World! 该页面已被访问 {} 次。\n'.format(count)
if __name__ == '__main__':
try:
ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.0"
addr = len(sys.argv) < 2 and "0.0.0.0" or sys.argv[1]
port = len(sys.argv) < 3 and 80 or int(sys.argv[2])
HandlerClass.protocol_version = Protocol
httpd = ServerClass((addr, port), HandlerClass)
sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1], "..."
httpd.serve_forever()
except:
exit()
```
#### index.html
生成一个临时的 `index.html` 文件其内容会被 `index.py` 更新
```bash
$ touch index.html
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
```
#### Dockerfile
编写 `Dockerfile` 文件内容为
```docker
FROM python:2.7
WORKDIR /code
```dockerfile
FROM python:3.6-alpine
ADD . /code
EXPOSE 80
CMD python index.py
WORKDIR /code
RUN pip install redis flask
CMD ["python", "app.py"]
```
### haproxy 目录
编写 `haproxy.cfg` 文件内容为
```bash
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#### docker-compose.yml
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
listen stats
bind 0.0.0.0:70
stats enable
stats uri /
frontend balancer
bind 0.0.0.0:80
mode http
default_backend web_backends
backend web_backends
mode http
option forwardfor
balance roundrobin
server weba weba:80 check
server webb webb:80 check
server webc webc:80 check
option httpchk GET /
http-check expect status 200
```
### docker-compose.yml
编写 `docker-compose.yml` 文件这个是 `Compose` 使用的主模板文件内容十分简单指定 3 `web` 容器以及 1 `haproxy` 容器
编写 `docker-compose.yml` 文件这个是 Compose 使用的主模板文件
```yaml
version: "3"
version: '3'
services:
weba:
build: ./web
expose:
- 80
webb:
build: ./web
expose:
- 80
webc:
build: ./web
expose:
- 80
haproxy:
image: haproxy:latest
volumes:
- ./haproxy:/haproxy-override
- ./haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
web:
build: .
ports:
- "80:80"
- "70:70"
expose:
- "80"
- "70"
- "5000:5000"
redis:
image: "redis:alpine"
```
### 运行 compose 项目
现在 `compose-haproxy-web` 目录结构如下
```bash
compose-haproxy-web
├── docker-compose.yml
├── haproxy
│ └── haproxy.cfg
└── web
├── Dockerfile
├── index.html
└── index.py
```
在该目录下执行 `docker-compose up` 命令会整合输出所有容器的输出
#### 运行 compose 项目
```bash
$ docker-compose up
Recreating composehaproxyweb_webb_1...
Recreating composehaproxyweb_webc_1...
Recreating composehaproxyweb_weba_1...
Recreating composehaproxyweb_haproxy_1...
Attaching to composehaproxyweb_webb_1, composehaproxyweb_webc_1, composehaproxyweb_weba_1, composehaproxyweb_haproxy_1
```
此时访问本地 `80` 端口会经过 `haproxy` 自动转发到后端的某个 web 容器上刷新页面可以观察到访问的容器地址的变化
访问本地 `70` 端口可以查看到 `haproxy` 的统计信息
此时访问本地 `5000` 端口每次刷新页面计数就会加 1

View File

@@ -1,6 +1,6 @@
## 使用 WordPress
本小节内容适合 `PHP` 开发人员阅读
> 本小节内容适合 `PHP` 开发人员阅读
`Compose` 可以很便捷的让 `Wordpress` 运行在一个独立的环境中
@@ -10,14 +10,18 @@
### 创建 `docker-compose.yml` 文件
`docker-compose.yml` 文件将开启一个 `wordpress` 服务和一个独立的 `MySQL` 实例
[`docker-compose.yml`](https://github.com/yeasy/docker_practice/blob/master/compose/demo/wordpress/docker-compose.yml) 文件将开启一个 `wordpress` 服务和一个独立的 `MySQL` 实例
```yaml
version: "3"
services:
db:
image: mysql:5.7
image: mysql:8.0
command:
- --default_authentication_plugin=mysql_native_password
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
volumes:
- db_data:/var/lib/mysql
restart: always
@@ -39,7 +43,7 @@ services:
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
db_data:
```
### 构建并运行项目

View File

@@ -6,7 +6,7 @@
### `attach` 命令
`docker attach` Docker 自带的命令下面示例如何使用该命令
下面示例如何使用 `docker attach` 命令
```bash
$ docker run -dit ubuntu

View File

@@ -7,7 +7,7 @@
如果不使用 `-d` 参数运行容器
```bash
$ docker run ubuntu:17.10 /bin/sh -c "while true; do echo hello world; sleep 1; done"
$ docker run ubuntu:18.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
hello world
hello world
hello world
@@ -19,7 +19,7 @@ hello world
如果使用了 `-d` 参数运行容器
```bash
$ docker run -d ubuntu:17.10 /bin/sh -c "while true; do echo hello world; sleep 1; done"
$ docker run -d ubuntu:18.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
77b2dc01fe0f3f1265df143181e7b9af5e05279a884f4776ee75350ea9d8017a
```
@@ -32,7 +32,7 @@ $ docker run -d ubuntu:17.10 /bin/sh -c "while true; do echo hello world; sleep
```
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
77b2dc01fe0f ubuntu:17.10 /bin/sh -c 'while tr 2 minutes ago Up 1 minute agitated_wright
77b2dc01fe0f ubuntu:18.04 /bin/sh -c 'while tr 2 minutes ago Up 1 minute agitated_wright
```
要获取容器的输出信息可以通过 `docker container logs` 命令

View File

@@ -4,9 +4,9 @@
如果要导出本地某个容器可以使用 `docker export` 命令
```bash
$ docker ps -a
$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7691a814370e ubuntu:14.04 "/bin/bash" 36 hours ago Exited (0) 21 hours ago test
7691a814370e ubuntu:18.04 "/bin/bash" 36 hours ago Exited (0) 21 hours ago test
$ docker export 7691a814370e > ubuntu.tar
```

View File

@@ -11,7 +11,7 @@
例如下面的命令输出一个 Hello World之后终止容器
```bash
$ docker run ubuntu:14.04 /bin/echo 'Hello world'
$ docker run ubuntu:18.04 /bin/echo 'Hello world'
Hello world
```
@@ -20,7 +20,7 @@ Hello world
下面的命令则启动一个 bash 终端允许用户进行交互
```bash
$ docker run -t -i ubuntu:14.04 /bin/bash
$ docker run -t -i ubuntu:18.04 /bin/bash
root@af8bae53bdd3:/#
```

View File

@@ -9,9 +9,9 @@
终止状态的容器可以用 `docker container ls -a` 命令看到例如
```bash
docker ps -a
docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ba267838cc1b ubuntu:14.04 "/bin/bash" 30 minutes ago Exited (0) About a minute ago trusting_newton
ba267838cc1b ubuntu:18.04 "/bin/bash" 30 minutes ago Exited (0) About a minute ago trusting_newton
98e5efa7d997 training/webapp:latest "python app.py" About an hour ago Exited (0) 34 minutes ago backstabbing_pike
```

View File

@@ -4,4 +4,4 @@ CoreOS 的设计是为你提供能够像谷歌一样的大型互联网公司一
CoreOS 的安装文件和运行依赖非常小,它提供了精简的 Linux 系统它使用 Linux 容器在更高的抽象层来管理你的服务而不是通过常规的 YUM APT 来安装包
同时CoreOS 几乎可以运行在任何平台VirtualBox, Amazon EC2, QEMU/KVM, VMware OpenStack 等等甚至你所使用的硬件环境
同时CoreOS 几乎可以运行在任何平台`VirtualBox`, `Amazon EC2`, `QEMU/KVM`, `VMware` `OpenStack`

View File

@@ -1,8 +1,6 @@
# CoreOS介绍
# CoreOS 介绍
提起 Docker我们不得不提的就是 [CoreOS](https://coreos.com/).
CoreOS Docker 甚至容器技术的发展都带来了巨大的推动作用其提供了运行现代基础设施的特性支持大规模服务部署使得在基于最小化的现代操作系统上构建规模化的计算仓库成为了可能
[CoreOS](https://coreos.com/) 对 Docker 甚至容器技术的发展都带来了巨大的推动作用。其提供了运行现代基础设施的特性,支持大规模服务部署,使得在基于最小化的现代操作系统上构建规模化的计算仓库成为了可能。
# CoreOS 特性
@@ -14,7 +12,7 @@ CoreOS 被设计成一个基于容器的最小化的现代操作系统。它比
利用主动和被动双分区方案来更新 OS使用分区作为一个单元而不是一个包一个包的更新这使得每次更新变得快速可靠而且很容易回滚
## Docker容器
## Docker 容器
应用作为 Docker 容器运行在 CoreOS 容器以包的形式提供最大得灵活性并且可以在几毫秒启动
@@ -30,4 +28,4 @@ CoreOS 可以在一个机器上很好地运行,但是它被设计用来搭建
## 服务发现
很容易定位服务在集群的那里运行并当发生变化时进行通知它是复杂高动态集群必不可少的 CoreOS 中构建高可用和自动故障负载
很容易定位服务在集群的那里运行并当发生变化时进行通知它是复杂高动态集群必不可少的

View File

@@ -6,17 +6,8 @@
`CoreOS` 的第一个重要组件就是使用 `etcd` 来实现的服务发现 `CoreOS` `etcd` 默认以 `rkt` 容器方式运行
```bash
$ rkt list
UUID APP IMAGE NAME STATE CREATED STARTED NETWORKS
57581644 etcd quay.io/coreos/etcd:v3.2.10 running 1 minute ago 1 minute ago
```
`etcd` 使用方法请查看 [etcd 章节](../etcd/)
`etcd` 使用方法请查看 [etcd 章节](../etcd/)
## 容器管理
第二个组件就是 `Docker`它用来运行你的代码和应用`CoreOS` 内置 `Docker`具体使用请参考本书其他章节
`CoreOS` 也内置了由自己开发的容器 `Rkt``Rkt` 不属于本书的讨论范围这里不再赘述

View File

@@ -1,85 +0,0 @@
# 快速搭建 CoreOS 集群
在这里我们要搭建一个集群环境毕竟单机环境没有什么挑战不是
然后为了在你的电脑运行一个集群环境我们使用 Vagrant
*Vagrant 的使用这里不再阐述请自行学习*
如果你第一次接触 CoreOS 这样的分布式平台运行一个集群看起来好像一个很复杂的任务这里我们给你展示在本地快速搭建一个 CoreOS 集群环境是多么的容易
## 准备工作
首先要确认在你本地的机器上已经安装了最新版本的 Virtualbox, Vagrant git
这是我们可以在本地模拟集群环境的前提条件如果你已经拥有请继续否则自行搜索学习
## 配置工作
CoreOS 官方代码库获取基本配置并进行修改
首先获取模板配置文件
```bash
$ git clone https://github.com/coreos/coreos-vagrant
$ cd coreos-vagrant
$ cp user-data.sample user-data
```
获取新的 token
```bash
$ curl https://discovery.etcd.io/new
```
把获取的 token 放到 user-data 文件中示例如下
```yml
#cloud-config
coreos:
etcd:
discovery: https://discovery.etcd.io/<token>
```
## 启动集群
默认情况下CoreOS Vagrantfile 将会启动单机
我们需要复制并修改 config.rb.sample 文件.
复制文件
```bash
cp config.rb.sample config.rb
```
修改集群配置参数 num_instances为3
启动集群
```bash
vagrant up
=>
Bringing machine 'core-01' up with 'virtualbox' provider...
Bringing machine 'core-02' up with 'virtualbox' provider...
Bringing machine 'core-03' up with 'virtualbox' provider...
==> core-01: Box 'coreos-alpha' could not be found. Attempting to find and install...
core-01: Box Provider: virtualbox
core-01: Box Version: >= 0
==> core-01: Adding box 'coreos-alpha' (v0) for provider: virtualbox
core-01: Downloading: http://storage.core-os.net/coreos/amd64-usr/alpha/coreos_production_vagrant.box
core-01: Progress: 46% (Rate: 6105k/s, Estimated time remaining: 0:00:16)
```
添加 ssh 的公匙
```bash
ssh-add ~/.vagrant.d/insecure_private_key
```
连接集群中的第一台机器
```bash
vagrant ssh core-01 -- -A
```

BIN
cover.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 KiB

View File

@@ -1,11 +1,9 @@
# Docker 数据管理
![](https://docs.docker.com/engine/admin/volumes/images/types-of-mounts-volume.png)
![](_images/types-of-mounts.png)
这一章介绍如何在 Docker 内部以及容器之间管理数据在容器中管理数据主要有两种方式
* 数据卷Volumes
* 挂载主机目录 (Bind mounts)
Docker 1.13 版本引进了新的管理命令management commands Docker 1.13+ 推荐使用 `docker volume` 子命令来管理 Docker 数据卷

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -1,9 +1,5 @@
## 挂载主机目录
### 选择 -v 还是 -mount 参数
Docker 新用户应该选择 `--mount` 参数经验丰富的 Docker 使用者对 `-v` 或者 `--volume` 已经很熟悉了但是推荐使用 `--mount` 参数
### 挂载一个主机目录作为数据卷
使用 `--mount` 标记可以指定挂载一个本地主机的目录到容器中去
@@ -30,10 +26,10 @@ $ docker run -d -P \
python app.py
```
加了 `readonly` 之后就挂载为 `只读` 如果你在容器内 `/src/webapp` 目录新建文件会显示如下错误
加了 `readonly` 之后就挂载为 `只读` 如果你在容器内 `/opt/webapp` 目录新建文件会显示如下错误
```bash
/src/webapp # touch new.txt
/opt/webapp # touch new.txt
touch: new.txt: Read-only file system
```
@@ -68,12 +64,12 @@ $ docker inspect web
$ docker run --rm -it \
# -v $HOME/.bash_history:/root/.bash_history \
--mount type=bind,source=$HOME/.bash_history,target=/root/.bash_history \
ubuntu:17.10 \
ubuntu:18.04 \
bash
root@2affd44b4667:/# history
1 ls
2 diskutil list
2 diskutil list
```
这样就可以记录在容器输入过的命令了

Some files were not shown because too many files have changed in this diff Show More