前段时间与同事交流docker的安装包层次结构,并沟通相关每个文件的作用,但是一直没有进行文字备份,过去已经一月有余,还是将其记录下来,供后续工作参考
默认docker启动会将目录安装在/var/lib/docker中,不过建议可以修改安装目录.
防止系统盘空间占用过大,最好选择存储空间较大的分区.
docker目录:
containers当前容器的集合(相当于docker ps -a)
目录是容器的配置信息及当前状态.
常用的包括容器配置信息, 网络信息,日志,都是来源于此,默认存储方式json
我们平时使用的docker inspect , docker logs, docker ps 都是来自于文件夹
一般用于docker容器重启时,恢复配置使用的依据,由于挂起方式是基础环境,没有办法像VM软件的挂起可以冻结进程,也是docker类似半虚拟容器很难实现真正的将运行容器进行分发,故此如果想实现有状态的运行容器漂移是仍是十分困难.
hostname 主机名称
hosts 容器重启
resolv.conf是DNS服务,默认是拷贝/etc/resolv.conf的配置
hostconfig.json是核心配置之一, 包括网络, CPU, MEM等,dockerrun选项配置形成的容器设置都可以在此处查询到.
config.json是核心docker状态管理文件, 由她加载上述所有文件
config.json 是核心docker状态管理文件, 由她加载上述所有文件
[plain] view plain copy
1. {
2. "State": {
3. "Running": false,
4. "Paused": false,
5. "Restarting": false,
6. "OOMKilled": false,
7. "Dead": false,
8. "Pid": 0,
9. "ExitCode": 0,
10. "Error": "",
11. "StartedAt": "2015-10-10T07:36:31.250795069Z",
12. "FinishedAt": "2015-10-10T07:37:09.587772608Z"
13. },
14. "ID": "02bbc65a5c2a285c34565fd9b0b3b485772faaf968a2f2eb3df1fff649119def",
15. "Created": "2015-10-10T07:36:30.400677786Z",
16. "Path": "/bin/bash",
17. "Args": [],
18. "Config": {
19. "Hostname": "02bbc65a5c2a",
20. "Domainname": "",
21. "User": "",
22. "AttachStdin": true,
23. "AttachStdout": true,
24. "AttachStderr": true,
25. "PortSpecs": null,
26. "ExposedPorts": null,
27. "Tty": true,
28. "OpenStdin": true,
29. "StdinOnce": true,
30. "Env": null,
31. "Cmd": [
32. "/bin/bash"
33. ],
34. "Image": "docker.io/coreos/apache",
35. "Volumes": {
36. "/data0": {}
37. },
38. "VolumeDriver": "",
39. "WorkingDir": "",
40. "Entrypoint": null,
41. "NetworkDisabled": false,
42. "MacAddress": "",
43. "OnBuild": null,
44. "Labels": {}
45. },
46. "Image": "87026dcb00443eb7f1725b1c9f4fb8210027a19364103854a1e5f606b95019ff",
47. "NetworkSettings": {
48. "Bridge": "",
49. "EndpointID": "",
50. "Gateway": "",
51. "GlobalIPv6Address": "",
52. "GlobalIPv6PrefixLen": 0,
53. "HairpinMode": false,
54. "IPAddress": "",
55. "IPPrefixLen": 0,
56. "IPv6Gateway": "",
57. "LinkLocalIPv6Address": "",
58. "LinkLocalIPv6PrefixLen": 0,
59. "MacAddress": "",
60. "NetworkID": "",
61. "PortMapping": null,
62. "Ports": null,
63. "SandboxKey": "",
64. "SecondaryIPAddresses": null,
65. "SecondaryIPv6Addresses": null
66. },
67. "ResolvConfPath": "/var/lib/docker/containers/02bbc65a5c2a285c34565fd9b0b3b485772faaf968a2f2eb3df1fff649119def/resolv.conf",
68. "HostnamePath": "/var/lib/docker/containers/02bbc65a5c2a285c34565fd9b0b3b485772faaf968a2f2eb3df1fff649119def/hostname",
69. "HostsPath": "/var/lib/docker/containers/02bbc65a5c2a285c34565fd9b0b3b485772faaf968a2f2eb3df1fff649119def/hosts",
70. "LogPath": "/var/lib/docker/containers/02bbc65a5c2a285c34565fd9b0b3b485772faaf968a2f2eb3df1fff649119def/02bbc65a5c2a285c34565fd9b0b3b485772faaf968a2f2eb3df1fff649119def-json.log",
71. "Name": "/determined_poincare",
72. "Driver": "devicemapper",
73. "ExecDriver": "native-0.2",
74. "MountLabel": "",
75. "ProcessLabel": "",
76. "RestartCount": 0,
77. "UpdateDns": false,
78. "MountPoints": {
79. "/data0": {
80. "Name": "53938b2752dc6f84475657a57ce87d45a329d3815426c1f0988c18b6bbf2df86",
81. "Destination": "/data0",
82. "Driver": "local",
83. "RW": true,
84. "Source": "",
85. "Relabel": ""
86. }
87. },
88. "Volumes": {},
89. "VolumesRW": {},
90. "AppArmorProfile": ""
91. }
XXX.log 是容器log日志,也仅有启动容器时,运行命令的日志,其他如后台程序的日志并不在此日志中.
devicemapper是以ID为标识存储镜像和容器,可以说devicemapper是最核心的部分,同时也是最容易存储超标的部分,其是lvm的软件之docker主要用了他的快照功能,完成image的思想基石,containers和image的json文件都是描述,真正存储数据的则是devicemapper/data.
其中包括临时容器和镜像文件, 尽管我们是容器内部的文件拷贝,也会促使data文件的增大,后续打算找个专题来解释他吧,docker的封装devicemapper的API是很不错,有兴趣可以参考/github.com/docker/docker/daemon/graphdriver/devmapper/driver.go仅仅对外暴漏数个接口,具体实现deviceset.go中.
graph存储镜像信息,使用json方式存储描述,真正数据也是存储在devicemapper中,镜像ID则是devicemapper存储的ID.
devicemapper具体可参考:graph.go的Register(img*image.Image,layerDataio.Reader)函数
镜像内容包括:镜像ID,父镜像ID,父镜像的容器,另每个镜像都有一个初始镜像,可以追溯
[java] view plain copy
1. // Create creates a new image and registers it in the graph.
2. // 创建一个新的镜像
3. func (graph *Graph) Create(layerData io.Reader, containerID, containerImage, comment, author string, containerConfig, config *runconfig.Config) (*image.Image, error) {
4. // 初始化镜像实例
5. img := &image.Image{
6. // 生成镜像ID
7. // 命令
8. // 时间
9. // docker版本
10. // 作者
11. // 相关container配置, 请查看graph/**/json
12. Architecture: runtime.GOARCH,
13. OS: runtime.GOOS,
14. }
15.
16.
17. // 非初始镜像,则设置镜像父子关系
18. if containerID != "" {
19. img.Parent = containerImage
20. img.Container = containerID
21. img.ContainerConfig = *containerConfig
22. }
23.
24.
25. // 注册镜像
26. if err := graph.Register(img, layerData); err != nil {
27. return nil, err
28. }
29. return img, nil
30. }
vfs是我们使用不定向挂载时引用,比如说我们-vdata0则默认使用vfs做为挂载路径,使用dockerfile时较为常用
volumes是挂载使用的映射关系,对应挂载源与挂载路径的关系,同时拥有ID,用于可以多个容器使用一个挂在源
linkgraph.db是graph存储镜像之间的关联关系,是初始化graph对象的依据.同时,graph文件夹的信息与linkgraph.db是数据重合的.