Skip to content

Commit defa08e

Browse files
ShiShushengJava-Edge
authored andcommitted
优化目录和内容
0 parents  commit defa08e

File tree

556 files changed

+93768
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

556 files changed

+93768
-0
lines changed

.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Java template
3+
# Compiled class file
4+
*.class
5+
6+
# Log file
7+
*.log
8+
9+
# BlueJ files
10+
*.ctxt
11+
12+
# Mobile Tools for Java (J2ME)
13+
.mtj.tmp/
14+
15+
# Package Files #
16+
*.jar
17+
*.war
18+
*.nar
19+
*.ear
20+
*.zip
21+
*.tar.gz
22+
*.rar
23+
24+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
25+
hs_err_pid*
26+
27+
.DS_Store
28+
.idea/JavaEdge.iml
29+
.idea/compiler.xml
30+
.idea/inspectionProfiles/
31+
.idea/misc.xml
32+
.idea/modules.xml
33+
.idea/vcs.xml
34+
.idea/workspace.xml
35+
Python/.DS_Store
36+
大数据/.DS_Store
37+
操作系统/.DS_Store
38+
数据存储/.DS_Store
39+
面试题系列/.DS_Store
40+
41+
.metals/metals.h2.db
42+
.metals/metals.log
43+
.vscode/settings.json
44+
45+
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# 1 Docker架构和底层技术简介
2+
![Docker Platform](https://upload-images.jianshu.io/upload_images/4685968-8a50f52c8c208765.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
3+
![Docker Engine](https://upload-images.jianshu.io/upload_images/4685968-94cbf0ab167019a5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4+
![](https://upload-images.jianshu.io/upload_images/4685968-de2befc2c04d25f8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
5+
![](https://upload-images.jianshu.io/upload_images/4685968-f5582bfe970d0c13.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
6+
![Docker Architecture](https://upload-images.jianshu.io/upload_images/4685968-468459a0cd76a9f0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
7+
![底层技术支持](https://upload-images.jianshu.io/upload_images/4685968-2483bf3e509b4f14.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
8+
# 2 Docker Image概述
9+
![](https://upload-images.jianshu.io/upload_images/4685968-70ef1300c4bdfbcb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
10+
![dockerimage结构](https://upload-images.jianshu.io/upload_images/4685968-5e3ffdc7ede27900.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
11+
从基本的看起,一个典型的 Linux 文件系统由 bootfs 和 rootfs 两部分组成,
12+
- bootfs(boot file system) 主要包含 bootloader 和 kernel,bootloader 主要用于引导加载 kernel,当 kernel 被加载到内存中后 bootfs 会被 umount 掉
13+
- rootfs (root file system) 包含的就是典型 Linux 系统中的/dev,/proc,/bin,/etc 等标准目录和文件
14+
![docker image 中最基础的两层结构](https://upload-images.jianshu.io/upload_images/4685968-fe22863d36925635.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
15+
不同的 linux 发行版(如 ubuntu 和 CentOS ) 在 rootfs 这一层会有所区别,体现发行版本的差异性
16+
传统的 Linux 加载 bootfs 时会先将 rootfs 设为 read-only,然后在系统自检之后将 rootfs 从 read-only 改为 read-write,然后就可在 rootfs 上进行读写操作了
17+
但 Docker 在 bootfs 自检完毕之后并不会把 rootfs 的 read-only 改为 read-write,而是利用 union mount(UnionFS 的一种挂载机制)将 image 中的其他的 layer 加载到之前的 read-only 的 rootfs 层之上,每一层 layer 都是 rootfs 的结构,并且是read-only 的。所以,我们是无法修改一个已有镜像里面的 layer 的!只有当我们创建一个容器,也就是将 Docker 镜像进行实例化,系统会分配一层空的 read-write 的 rootfs ,用于保存我们做的修改。一层 layer 所保存的修改是增量式的,就像 git 一样
18+
![](https://upload-images.jianshu.io/upload_images/4685968-46da122fa66ef4fc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
19+
## 2.2 image的获取
20+
### image的获取-1
21+
![](https://upload-images.jianshu.io/upload_images/4685968-6bb5b24cad291667.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
22+
### image的获取-2
23+
![image的获取-2](https://upload-images.jianshu.io/upload_images/4685968-20c81225745462c3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
24+
![sudo docker pull ubuntu:16.04](https://upload-images.jianshu.io/upload_images/4685968-1d89f39390415913.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
25+
![](https://upload-images.jianshu.io/upload_images/4685968-7f6b1690bce02627.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
26+
![官方镜像仓库](https://upload-images.jianshu.io/upload_images/4685968-c7a0f3cf52174d23.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
27+
# 3 DIY Base Image
28+
![无需再用 sudo 权限](https://upload-images.jianshu.io/upload_images/4685968-24518ba6f7cb3f97.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
29+
![](https://upload-images.jianshu.io/upload_images/4685968-81717c25f8bf2f20.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
30+
![](https://upload-images.jianshu.io/upload_images/4685968-1b7bde9a7c7822e0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
31+
![](https://upload-images.jianshu.io/upload_images/4685968-3e4122555b3c50af.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
32+
![](https://upload-images.jianshu.io/upload_images/4685968-3680db12feae63a7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
33+
![运行结果](https://upload-images.jianshu.io/upload_images/4685968-8aeed6a6d3115375.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
34+
![vim Dockerfile](https://upload-images.jianshu.io/upload_images/4685968-d3d6e05936a5066f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
35+
![docker build -t root/hello-world .](https://upload-images.jianshu.io/upload_images/4685968-02b6d659365997ec.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
36+
![](https://upload-images.jianshu.io/upload_images/4685968-542b9b43e06f7fdb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
37+
![docker run root/hello-world](https://upload-images.jianshu.io/upload_images/4685968-563e8925bbde05e5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
38+
# 4 初识Container
39+
![什么是 Container](https://upload-images.jianshu.io/upload_images/4685968-62a26b73ac9a7279.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
40+
![](https://upload-images.jianshu.io/upload_images/4685968-43077ea9a69b27f2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
41+
docker rm 默认就是移除 container
42+
docker images = docker image ls
43+
![](https://upload-images.jianshu.io/upload_images/4685968-5141e2b3adb62b25.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
44+
- docker rmi = docker image rm
45+
![](https://upload-images.jianshu.io/upload_images/4685968-bad602072d2e7470.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
46+
![docker ps -a](https://upload-images.jianshu.io/upload_images/4685968-4cfa4be425ec20eb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
47+
![只显示 id](https://upload-images.jianshu.io/upload_images/4685968-c51873bbae28658e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
48+
![删除全部](https://upload-images.jianshu.io/upload_images/4685968-ef425e27274a4b7b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
49+
# 5 构建自己的Docker镜像
50+
- docker container commit
51+
从容器创建一个新的镜像
52+
```
53+
-a :提交的镜像作者;
54+
55+
-c :使用Dockerfile指令来创建镜像;
56+
57+
-m :提交时的说明文字;
58+
59+
-p :在commit时,将容器暂停。
60+
```
61+
![](https://upload-images.jianshu.io/upload_images/4685968-1132c54fcc2051f9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
62+
- docker image build
63+
使用 Dockerfile 创建镜像
64+
```
65+
使用当前目录的 Dockerfile 创建镜像,标签为 runoob/ubuntu:v1。
66+
67+
docker build -t runoob/ubuntu:v1 .
68+
使用URL github.com/creack/docker-firefox 的 Dockerfile 创建镜像。
69+
70+
docker build github.com/creack/docker-firefox
71+
也可以通过 -f Dockerfile 文件的位置:
72+
73+
$ docker build -f /path/to/a/Dockerfile .
74+
在 Docker 守护进程执行 Dockerfile 中的指令前,首先会对 Dockerfile 进行语法检查,有语法错误时会返回:
75+
76+
$ docker build -t test/myapp .
77+
Sending build context to Docker daemon 2.048 kB
78+
Error response from daemon: Unknown instruction: RUNCMD
79+
```
80+
![](https://upload-images.jianshu.io/upload_images/4685968-22c686d535b6da64.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
81+
- docker run
82+
创建一个新的容器并运行一个命令
83+
```
84+
-a stdin: 指定标准输入输出内容类型,可选 STDIN/STDOUT/STDERR 三项;
85+
86+
-d: 后台运行容器,并返回容器ID;
87+
88+
-i: 以交互模式运行容器,通常与 -t 同时使用;
89+
90+
-p: 端口映射,格式为:主机(宿主)端口:容器端口
91+
92+
-t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
93+
94+
--name="nginx-lb": 为容器指定一个名称;
95+
96+
--dns 8.8.8.8: 指定容器使用的DNS服务器,默认和宿主一致;
97+
98+
--dns-search example.com: 指定容器DNS搜索域名,默认和宿主一致;
99+
100+
-h "mars": 指定容器的hostname;
101+
102+
-e username="ritchie": 设置环境变量;
103+
104+
--env-file=[]: 从指定文件读入环境变量;
105+
106+
--cpuset="0-2" or --cpuset="0,1,2": 绑定容器到指定CPU运行;
107+
108+
-m :设置容器使用内存最大值;
109+
110+
--net="bridge": 指定容器的网络连接类型,支持 bridge/host/none/container: 四种类型;
111+
112+
--link=[]: 添加链接到另一个容器;
113+
114+
--expose=[]: 开放一个端口或一组端口;
115+
```
116+
117+
docker run -it ubuntu
118+
![](https://upload-images.jianshu.io/upload_images/4685968-c607a53211cb5c8a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
119+
120+
新创建的container
121+
![](https://upload-images.jianshu.io/upload_images/4685968-6faa797109b122b9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
122+
![docker commit wizardly_feynman root/ubuntu-vim](https://upload-images.jianshu.io/upload_images/4685968-5ac081dde9692622.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
123+
![](https://upload-images.jianshu.io/upload_images/4685968-c6c154f9ce89581e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
124+
![删除刚才创建的 docker](https://upload-images.jianshu.io/upload_images/4685968-a9ede667b30d5869.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
125+
以上新建方式不推荐,下面看
126+
## 5.2 dockerfile 创建方法
127+
![](https://upload-images.jianshu.io/upload_images/4685968-2a0527b19d94ece5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
128+
![](https://upload-images.jianshu.io/upload_images/4685968-6ea1ff0840293da7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
129+
130+
# 6 Dockerfile语法梳理及最佳实践
131+
## 6.1 FROM
132+
![](https://upload-images.jianshu.io/upload_images/4685968-351563c28498fae3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
133+
![](https://upload-images.jianshu.io/upload_images/4685968-63e54b4e97510154.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
134+
135+
## 6.2 LABEL
136+
就如代码中的注释
137+
![](https://upload-images.jianshu.io/upload_images/4685968-71c14853d754b1df.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
138+
![](https://upload-images.jianshu.io/upload_images/4685968-4096084d19b9dd6f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
139+
140+
6.3 RUN
141+
![](https://upload-images.jianshu.io/upload_images/4685968-a7fc82e0c33b03b7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
142+
![](https://upload-images.jianshu.io/upload_images/4685968-ecc90a7b741e4412.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
143+
144+
## 6.4 WORKDIR
145+
![](https://upload-images.jianshu.io/upload_images/4685968-6441dd56a3956296.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
146+
![](https://upload-images.jianshu.io/upload_images/4685968-4d29341e8b3e9323.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
147+
148+
## ADD and COPY
149+
![](https://upload-images.jianshu.io/upload_images/4685968-71d2a8195bfe6ab3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
150+
![](https://upload-images.jianshu.io/upload_images/4685968-98875a7091f3738a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
151+
152+
153+
## ENV
154+
![](https://upload-images.jianshu.io/upload_images/4685968-36cdabfbabb60071.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
155+
![](https://upload-images.jianshu.io/upload_images/4685968-4fb9e6d5eacf5a20.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
156+
157+
## VOLUME and EXPOSE
158+
![](https://upload-images.jianshu.io/upload_images/4685968-453c6e29e2cb3b23.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
159+
160+
## CMD and ENTRYPOINT
161+
![](https://upload-images.jianshu.io/upload_images/4685968-07127360d1b00697.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
162+
163+
# 7
164+
![](https://upload-images.jianshu.io/upload_images/4685968-366e8c17aca38450.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
165+
166+
## Shell 和 Exec 格式
167+
![](https://upload-images.jianshu.io/upload_images/4685968-3d1fbaa8fbe03d23.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
168+
![](https://upload-images.jianshu.io/upload_images/4685968-a771d49d749e1fc5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

0 commit comments

Comments
 (0)