File tree Expand file tree Collapse file tree 7 files changed +25
-22
lines changed Expand file tree Collapse file tree 7 files changed +25
-22
lines changed Original file line number Diff line number Diff line change 3
3
See [CONTRIBUTING](CONTRIBUTING.md) for contribution guidelines.
4
4
-->
5
5
6
- ### Proposed changes (Mandatory)
6
+ ** Proposed changes (Mandatory)**
7
7
8
8
<!--
9
9
Tell us what you did and why:
13
13
And details in other paragraphs.
14
14
-->
15
15
16
- ### Fix issues (Optional)
16
+ ** Fix issues (Optional)**
17
17
18
18
<!--
19
19
Tell us what issues you fixed, e.g., fix #123
Original file line number Diff line number Diff line change 28
28
"github.com/etcd-io/etcd/releases/download",\
29
29
"github.com/tianon/gosu/releases/download",\
30
30
"github.com/yeasy/docker_practice",\
31
- "github.com/twang2218/gitlab-ce-zh.git",\
32
31
"github.com/AliyunContainerService/k8s-for-docker-desktop/raw",\
33
32
"dl-cdn.alpinelinux.org/alpine/edge/testing",\
34
33
"www.w3.org/1999/xhtml",\
Original file line number Diff line number Diff line change 8
8
9
9
容器存储层的生存周期和容器一样,容器消亡时,容器存储层也随之消亡。因此,任何保存于容器存储层的信息都会随容器删除而丢失。
10
10
11
- 按照 Docker 最佳实践的要求,容器不应该向其存储层内写入任何数据,容器存储层要保持无状态化。所有的文件写入操作,都应该使用 [ 数据卷(Volume)] ( ../data_management/volume.md ) 、或者绑定宿主目录 ,在这些位置的读写会跳过容器存储层,直接对宿主(或网络存储)发生读写,其性能和稳定性更高。
11
+ 按照 Docker 最佳实践的要求,容器不应该向其存储层内写入任何数据,容器存储层要保持无状态化。所有的文件写入操作,都应该使用 [ 数据卷(Volume)] ( ../data_management/volume.md ) 、或者 [ 绑定宿主目录 ] ( ../data_management/bind-mounts.md ) ,在这些位置的读写会跳过容器存储层,直接对宿主(或网络存储)发生读写,其性能和稳定性更高。
12
12
13
13
数据卷的生存周期独立于容器,容器消亡,数据卷不会消亡。因此,使用数据卷后,容器删除或者重新运行之后,数据却不会丢失。
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ RUN make -C /usr/src/redis install
80
80
``` docker
81
81
FROM debian:stretch
82
82
83
- RUN buildDeps='gcc libc6-dev make wget' \
83
+ RUN set -x; buildDeps='gcc libc6-dev make wget' \
84
84
&& apt-get update \
85
85
&& apt-get install -y $buildDeps \
86
86
&& wget -O redis.tar.gz "http://download.redis.io/releases/redis-5.0.3.tar.gz" \
@@ -177,17 +177,23 @@ Sending build context to Docker daemon 2.048 kB
177
177
或许你已经注意到了,` docker build ` 还支持从 URL 构建,比如可以直接从 Git repo 中构建:
178
178
179
179
``` bash
180
- $ docker build https://github.com/twang2218/gitlab-ce-zh.git#:11.1
181
-
182
- Sending build context to Docker daemon 2.048 kB
183
- Step 1 : FROM gitlab/gitlab-ce:11.1.0-ce.0
184
- 11.1.0-ce.0: Pulling from gitlab/gitlab-ce
185
- aed15891ba52: Already exists
186
- 773ae8583d14: Already exists
187
- ...
180
+ # $env:DOCKER_BUILDKIT=0
181
+ # export DOCKER_BUILDKIT=0
182
+
183
+ $ docker build -t hello-world https://github.com/docker-library/hello-world.git#master:amd64/hello-world
184
+
185
+ Step 1/3 : FROM scratch
186
+ --->
187
+ Step 2/3 : COPY hello /
188
+ ---> ac779757d46e
189
+ Step 3/3 : CMD [" /hello" ]
190
+ ---> Running in d2a513a760ed
191
+ Removing intermediate container d2a513a760ed
192
+ ---> 038ad4142d2b
193
+ Successfully built 038ad4142d2b
188
194
```
189
195
190
- 这行命令指定了构建所需的 Git repo,并且指定默认的 ` master ` 分支 ,构建目录为 ` /11.1 / ` ,然后 Docker 就会自己去 ` git clone ` 这个项目、切换到指定分支、并进入到指定目录后开始构建。
196
+ 这行命令指定了构建所需的 Git repo,并且指定分支为 ` master ` ,构建目录为 ` /amd64/hello-world / ` ,然后 Docker 就会自己去 ` git clone ` 这个项目、切换到指定分支、并进入到指定目录后开始构建。
191
197
192
198
### 用给定的 tar 压缩包构建
193
199
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ $ docker run --name webserver -d -p 80:80 nginx
16
16
17
17
这条命令会用 ` nginx ` 镜像启动一个容器,命名为 ` webserver ` ,并且映射了 80 端口,这样我们可以用浏览器去访问这个 ` nginx ` 服务器。
18
18
19
- 如果是在 Linux 本机运行的 Docker,或者如果使用的是 Docker Desktop for Mac/Windows, 那么可以直接访问:< http://localhost > ;如果使用的是 Docker Toolbox,或者是在虚拟机 、云服务器上安装的 Docker,则需要将 ` localhost ` 换为虚拟机地址或者实际云服务器地址。
19
+ 如果是在本机运行的 Docker,那么可以直接访问:` http://localhost ` ,如果是在虚拟机 、云服务器上安装的 Docker,则需要将 ` localhost ` 换为虚拟机地址或者实际云服务器地址。
20
20
21
21
直接用浏览器访问的话,我们会看到默认的 Nginx 欢迎页面。
22
22
@@ -116,15 +116,15 @@ e43d811ce2f4 4 weeks ago /bin/sh -c #(nop) CMD ["nginx" "-g" "da
116
116
docker run --name web2 -d -p 81:80 nginx:v2
117
117
` ` `
118
118
119
- 这里我们命名为新的服务为 ` web2` ,并且映射到 ` 81` 端口。如果是 Docker Desktop for Mac/Windows 或 Linux 桌面的话,我们就可以直接访问 < http://localhost:81> 看到结果,其内容应该和之前修改后的 ` webserver` 一样。
119
+ 这里我们命名为新的服务为 ` web2` ,并且映射到 ` 81` 端口。访问 ` http://localhost:81` 看到结果,其内容应该和之前修改后的 ` webserver` 一样。
120
120
121
121
至此,我们第一次完成了定制镜像,使用的是 ` docker commit` 命令,手动操作给旧的镜像添加了新的一层,形成新的镜像,对镜像多层存储应该有了更直观的感觉。
122
122
123
123
# # 慎用 `docker commit`
124
124
125
125
使用 ` docker commit` 命令虽然可以比较直观的帮助理解镜像分层存储的概念,但是实际环境中并不会这样使用。
126
126
127
- 首先,如果仔细观察之前的 ` docker diff webserver` 的结果,你会发现除了真正想要修改的 ` /usr/share/nginx/html/index.html` 文件外,由于命令的执行,还有很多文件被改动或添加了。这还仅仅是最简单的操作,如果是安装软件包、编译构建,那会有大量的无关内容被添加进来,如果不小心清理, 将会导致镜像极为臃肿。
127
+ 首先,如果仔细观察之前的 ` docker diff webserver` 的结果,你会发现除了真正想要修改的 ` /usr/share/nginx/html/index.html` 文件外,由于命令的执行,还有很多文件被改动或添加了。这还仅仅是最简单的操作,如果是安装软件包、编译构建,那会有大量的无关内容被添加进来,将会导致镜像极为臃肿。
128
128
129
129
此外,使用 ` docker commit` 意味着所有对镜像的操作都是黑箱操作,生成的镜像也被称为 ** 黑箱镜像** ,换句话说,就是除了制作镜像的人知道执行过什么命令、怎么生成的镜像,别人根本无从得知。而且,即使是这个制作镜像的人,过一段时间后也无法记清具体的操作。这种黑箱镜像的维护工作是非常痛苦的。
130
130
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签]
10
10
11
11
具体的选项可以通过 ` docker pull --help ` 命令看到,这里我们说一下镜像名称的格式。
12
12
13
- * Docker 镜像仓库地址:地址的格式一般是 ` <域名/IP>[:端口号] ` 。默认地址是 Docker Hub。
13
+ * Docker 镜像仓库地址:地址的格式一般是 ` <域名/IP>[:端口号] ` 。默认地址是 Docker Hub(docker.io) 。
14
14
* 仓库名:如之前所说,这里的仓库名是两段式名称,即 ` <用户名>/<软件名> ` 。对于 Docker Hub,如果不给出用户名,则默认为 ` library ` ,也就是官方镜像。
15
15
16
16
比如:
@@ -40,9 +40,7 @@ Status: Downloaded newer image for ubuntu:18.04
40
40
有了镜像后,我们就能够以这个镜像为基础启动并运行一个容器。以上面的 ` ubuntu:18.04 ` 为例,如果我们打算启动里面的 ` bash ` 并且进行交互式操作的话,可以执行下面的命令。
41
41
42
42
``` bash
43
- $ docker run -it --rm \
44
- ubuntu:18.04 \
45
- bash
43
+ $ docker run -it --rm ubuntu:18.04 bash
46
44
47
45
root@e7009c6ce357:/# cat /etc/os-release
48
46
NAME=" Ubuntu"
Original file line number Diff line number Diff line change 2
2
3
3
** Docker** 最初是 ` dotCloud ` 公司创始人 [ Solomon Hykes] ( https://github.com/shykes ) 在法国期间发起的一个公司内部项目,它是基于 ` dotCloud ` 公司多年云服务技术的一次革新,并于 [ 2013 年 3 月以 Apache 2.0 授权协议开源] [ docker-soft ] ,主要项目代码在 [ GitHub] ( https://github.com/moby/moby ) 上进行维护。` Docker ` 项目后来还加入了 Linux 基金会,并成立推动 [ 开放容器联盟(OCI)] ( https://opencontainers.org/ ) 。
4
4
5
- ** Docker** 自开源后受到广泛的关注和讨论,至今其 [ GitHub 项目] ( https://github.com/moby/moby ) 已经超过 5 万 4 千个星标和一万多个 ` fork ` 。甚至由于 ` Docker ` 项目的火爆,在 ` 2013 ` 年底,[ dotCloud 公司决定改名为 Docker] ( https://www.docker.com/blog/dotcloud-is-becoming-docker-inc/ ) 。` Docker ` 最初是在 ` Ubuntu 12.04 ` 上开发实现的;` Red Hat ` 则从 ` RHEL 6.5 ` 开始对 ` Docker ` 进行支持;` Google ` 也在其 ` PaaS ` 产品中广泛应用 ` Docker ` 。
5
+ ** Docker** 自开源后受到广泛的关注和讨论,至今其 [ GitHub 项目] ( https://github.com/moby/moby ) 已经超过 5 万 7 千个星标和一万多个 ` fork ` 。甚至由于 ` Docker ` 项目的火爆,在 ` 2013 ` 年底,[ dotCloud 公司决定改名为 Docker] ( https://www.docker.com/blog/dotcloud-is-becoming-docker-inc/ ) 。` Docker ` 最初是在 ` Ubuntu 12.04 ` 上开发实现的;` Red Hat ` 则从 ` RHEL 6.5 ` 开始对 ` Docker ` 进行支持;` Google ` 也在其 ` PaaS ` 产品中广泛应用 ` Docker ` 。
6
6
7
7
** Docker** 使用 ` Google ` 公司推出的 [ Go 语言] ( https://golang.org/ ) 进行开发实现,基于 ` Linux ` 内核的 [ cgroup] ( https://zh.wikipedia.org/wiki/Cgroups ) ,[ namespace] ( https://en.wikipedia.org/wiki/Linux_namespaces ) ,以及 [ OverlayFS] ( https://docs.docker.com/storage/storagedriver/overlayfs-driver/ ) 类的 [ Union FS] ( https://en.wikipedia.org/wiki/Union_mount ) 等技术,对进程进行封装隔离,属于 [ 操作系统层面的虚拟化技术] ( https://en.wikipedia.org/wiki/Operating-system-level_virtualization ) 。由于隔离的进程独立于宿主和其它的隔离的进程,因此也称其为容器。最初实现是基于 [ LXC] ( https://linuxcontainers.org/lxc/introduction/ ) ,从 0.7 版本以后开始去除 ` LXC ` ,转而使用自行开发的 [ libcontainer] ( https://github.com/docker/libcontainer ) ,从 1.11 开始,则进一步演进为使用 [ runC] ( https://github.com/opencontainers/runc ) 和 [ containerd] ( https://github.com/containerd/containerd ) 。
8
8
You can’t perform that action at this time.
0 commit comments