Docker 镜像与容器存储目录结构精讲
很多朋友在初学 docker 的时候非常迷茫,不清楚 docker 是怎样的一种存储方式,并且也不清楚 docker 到底存储在什么地方。其实 docker 的镜像与容器都存储在 /var/lib/docker 下面,那么基于不同的系统又有不同的存储方式,在 ubuntu 下面存储方式为 AUFS;在 Centos 下面存储方式又是 device mapper,下面我们先来看一下 /var/lib/docker 目录,分别有三个阶段,看看在不同阶段都新增了那些东西及镜像与容器存储结构的变化:
环境:
系统:centos 7
内核:3.10.0-229.el7.x86_64
docker 版本: 1.8.2
- start docker 服务之后目录结构
- pull images 后目录结构
- run container 后目录结构
启动docker ,安装完 docker 后执行命令 systemctl start docker.service:
[root@docker-100 docker]# tree ./
./
├── containers
├── devicemapper
│ ├── devicemapper
│ │ ├── data
│ │ └── metadata
│ └── metadata
│ ├── base
│ ├── deviceset-metadata
│ └── transaction-metadata
├── graph
├── linkgraph.db
├── repositories-devicemapper
├── tmp
├── trust
└── volumes
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
前面我们说过,centos 下面 docker 使用 devicemapper 的存储方式,所以在 /var/lib/docker 下面出现了 devicemapper 目录
/var/lib/docker/devicemapper/devicemapper/ 目录下有两个文件:
/var/lib/docker/devicemapper/devicemapper/data
/var/lib/docker/devicemapper/devicemapper/metadata
它们是用来存储对应的存储池和相关的元数据。
/var/lib/docker/devicemapper/metadara/ 目录下有三个文件:
/var/lib/docker/devicemapper/metadata/base
/var/lib/docker/devicemapper/metadata/transaction-metadata
/var/lib/docker/devicemapper/metadata/deviceset-metadata
它们则是用来存放前面元数据的id、大小、以及UUID等信息。
当然,现在也存在几个空目录,我们等下来说,例如:
/var/lib/docker/containers
/var/lib/docker/devicemapper
/var/lib/docker/graph
/var/lib/docker/tmp
/var/lib/docker/trust
/var/lib/docker/volumes
还有一个文件,我们等下来说,先来了解下大致的目录结构:
/var/lib/docker/repositories-devicemapper
现在我们 docker pull centos 一个镜像下来 docker images 查看。接着再查看目录变化,对比之前的目录结构及文件变化:
[root@docker-100 ~]
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos latest ce20c473cd8a 8 weeks ago 172.3 MB
[root@docker-100 docker]# tree ./
./
├── containers
├── devicemapper
│ ├── devicemapper
│ │ ├── data
│ │ └── metadata
│ ├── metadata
│ │ ├── 168a69b6220279e6d5bd8dafd2edf71434a08e32b60a7060f7a705f64857169d
│ │ ├── 4234bfdd88f8ed2bc4607bd2ebba2d41d61e2693ad0d184e7b05e1b57f8b8b33
│ │ ├── 47d44cb6f252ea4f6aecf8a447972de5d9f9f2e2bec549a2f1d8f92557f4d05a
│ │ ├── 812e9d9d677f15c39277b2edc8f9bc07354c899483409bb07d1c13c2b9c33ec8
│ │ ├── base
│ │ ├── ce20c473cd8ac1fab6601529ce6a075743f2cf7a8f4cfed2216f8cfcb53bfc4e
│ │ ├── deviceset-metadata
│ │ └── transaction-metadata
│ └── mnt
│ ├── 168a69b6220279e6d5bd8dafd2edf71434a08e32b60a7060f7a705f64857169d
│ ├── 4234bfdd88f8ed2bc4607bd2ebba2d41d61e2693ad0d184e7b05e1b57f8b8b33
│ ├── 47d44cb6f252ea4f6aecf8a447972de5d9f9f2e2bec549a2f1d8f92557f4d05a
│ ├── 812e9d9d677f15c39277b2edc8f9bc07354c899483409bb07d1c13c2b9c33ec8
│ └── ce20c473cd8ac1fab6601529ce6a075743f2cf7a8f4cfed2216f8cfcb53bfc4e
├── graph
│ ├── 168a69b6220279e6d5bd8dafd2edf71434a08e32b60a7060f7a705f64857169d
│ │ ├── json
│ │ ├── layersize
│ │ └── tar-data.json.gz
│ ├── 4234bfdd88f8ed2bc4607bd2ebba2d41d61e2693ad0d184e7b05e1b57f8b8b33
│ │ ├── json
│ │ ├── layersize
│ │ └── tar-data.json.gz
│ ├── 47d44cb6f252ea4f6aecf8a447972de5d9f9f2e2bec549a2f1d8f92557f4d05a
│ │ ├── json
│ │ ├── layersize
│ │ └── tar-data.json.gz
│ ├── 812e9d9d677f15c39277b2edc8f9bc07354c899483409bb07d1c13c2b9c33ec8
│ │ ├── json
│ │ ├── layersize
│ │ └── tar-data.json.gz
│ ├── ce20c473cd8ac1fab6601529ce6a075743f2cf7a8f4cfed2216f8cfcb53bfc4e
│ │ ├── json
│ │ ├── layersize
│ │ └── tar-data.json.gz
│ └── _tmp
├── linkgraph.db
├── repositories-devicemapper
├── tmp
├── trust
└── volumes
20 directories, 27 files
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
当我 pull 一个镜像之后,子目录中增加了许多文件,最先看到的变化是在三个文件夹下面:
/var/lib/docker/devicemapper/medata/
/var/lib/docker/devicemapper/mnt/
/var/lib/docker/graph/
好,在这之前呢,我们先来看一下 docker 查看镜像中间件命令,docker images -a 显示所有图像(默认隐藏中间图像),我们在下图中可以清楚的看到,IMAGFE ID 分别为下图中的内容,也就是说,images centos 被下面四个中间件所支持:
centos ce20c473cd8a
<none> 4234bfdd88f8
<none> 812e9d9d677f
<none> 168a69b62202
<none> 47d44cb6f252
[root@docker-100 metadata]# docker images -a
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos latest ce20c473cd8a 8 weeks ago 172.3 MB
<none> <none> 4234bfdd88f8 8 weeks ago 172.3 MB
<none> <none> 812e9d9d677f 8 weeks ago 172.3 MB
<none> <none> 168a69b62202 8 weeks ago 172.3 MB
<none> <none> 47d44cb6f252 3 months ago 0 B
我们查看下 /var/lib/docker/devicemapper/metadata 目录下的内容
[root@docker-100 metadata]
{"device_id":1,"size":107374182400,"transaction_id":3,"initialized":true}
[root@docker-100 metadata]
{"device_id":2,"size":107374182400,"transaction_id":4,"initialized":false}
[root@docker-100 metadata]
{"device_id":3,"size":107374182400,"transaction_id":5,"initialized":false}
[root@docker-100 metadata]
{"device_id":4,"size":107374182400,"transaction_id":6,"initialized":false}
[root@docker-100 metadata]
{"device_id":5,"size":107374182400,"transaction_id":7,"initialized":false}
[root@docker-100 metadata]
{"device_id":6,"size":107374182400,"transaction_id":8,"initialized":false}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
可以清楚的看到,device_id (1、2、3、4、5、6)排序,也就是说,出了base这个文件以外,其他都是我们刚才添加的中间件,那么可以得出:
/var/lib/devicemapper/metadata 目录下的文件(除了base、 deviceset- metadata、transaction-medatata),其余的文件都是 images 本身和 images 的中间件信息;用来描述它们的id、大小、transaction_id、以及是否initialized,并且它们大小都是一样的。
变化的另一个目录是 /var/lib/docker/devicemapper 下的:
/var/lib/docker/devicemapper/mnt
它主要是用来挂载 images 和 Container 的目录,因为 devicemapper 本身就是通过在存储池中挂载的方式进行运行的。
最后一个目录则是 /var/lib/docker 下的:
/var/lib/docker/graph
我们来查看下 /var/lib/docker/graph 目录下到底有什么鬼?:
[root@docker-100 graph]# tree /var/lib/docker/graph/
/var/lib/docker/graph/
├── 168a69b6220279e6d5bd8dafd2edf71434a08e32b60a7060f7a705f64857169d
│ ├── json
│ ├── layersize
│ └── tar-data.json.gz
├── 4234bfdd88f8ed2bc4607bd2ebba2d41d61e2693ad0d184e7b05e1b57f8b8b33
│ ├── json
│ ├── layersize
│ └── tar-data.json.gz
├── 47d44cb6f252ea4f6aecf8a447972de5d9f9f2e2bec549a2f1d8f92557f4d05a
│ ├── json
│ ├── layersize
│ └── tar-data.json.gz
├── 812e9d9d677f15c39277b2edc8f9bc07354c899483409bb07d1c13c2b9c33ec8
│ ├── json
│ ├── layersize
│ └── tar-data.json.gz
├── ce20c473cd8ac1fab6601529ce6a075743f2cf7a8f4cfed2216f8cfcb53bfc4e
│ ├── json
│ ├── layersize
│ └── tar-data.json.gz
└── _tmp
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
原来是在每个images 本身及中间件下面多了三个文件,分别为(json、layersize、tar-data.json.gz),那我们来分别查看下这三个文件是干嘛的!
1、json (json 文件是用来描述 images 本身或者中间件的详细信息)
[root@docker-100 graph]# cat /var/lib/docker/graph/168a69b6220279e6d5bd8dafd2edf71434a08e32b60a7060f7a705f64857169d/json | python -mjson.tool
{
"Size": 172284372,
"architecture": "amd64",
"author": "The CentOS Project <cloud-ops@centos.org>",
"config": {
"AttachStderr": false,
"AttachStdin": false,
"AttachStdout": false,
"Cmd": null,
"Domainname": "",
"Entrypoint": null,
"Env": null,
"ExposedPorts": null,
"Hostname": "7aa5783a47d5",
"Image": "47d44cb6f252ea4f6aecf8a447972de5d9f9f2e2bec549a2f1d8f92557f4d05a",
"Labels": null,
"MacAddress": "",
"NetworkDisabled": false,
"OnBuild": null,
"OpenStdin": false,
"PublishService": "",
"StdinOnce": false,
"Tty": false,
"User": "",
"VolumeDriver": "",
"Volumes": null,
"WorkingDir": ""
},
"container": "7aa5783a47d56a1dd5b9f60dfa3dcc7ad83479f380137272e7493aa2e317d1cc",
"container_config": {
"AttachStderr": false,
"AttachStdin": false,
"AttachStdout": false,
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ADD file:125fe45519717bec39f64a67dfc5cd0ac1c8733963d71510ba770817d9466fcb in /"
],
"Domainname": "",
"Entrypoint": null,
"Env": null,
"ExposedPorts": null,
"Hostname": "7aa5783a47d5",
"Image": "47d44cb6f252ea4f6aecf8a447972de5d9f9f2e2bec549a2f1d8f92557f4d05a",
"Labels": null,
"MacAddress": "",
"NetworkDisabled": false,
"OnBuild": null,
"OpenStdin": false,
"PublishService": "",
"StdinOnce": false,
"Tty": false,
"User": "",
"VolumeDriver": "",
"Volumes": null,
"WorkingDir": ""
},
"created": "2015-10-13T23:29:00.133774303Z",
"docker_version": "1.8.2",
"id": "168a69b6220279e6d5bd8dafd2edf71434a08e32b60a7060f7a705f64857169d",
"os": "linux",
"parent": "47d44cb6f252ea4f6aecf8a447972de5d9f9f2e2bec549a2f1d8f92557f4d05a"
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
2、layersize (layersize 可以在字面意思就知道是用来表示中间件的大小)
[root@docker-100 graph]
172284372
3、tar-data.json.gz (tar-data.json: ASCII text, with very long lines,长文本格式,应该是用来描述依赖或者其他信息),解包查看发现很多乱码;但是可以查看,具体是做什么的目前还不清楚。
gunzip tar-data.json.gz
下面我们来看一下另一个文件 repositories-devicemapper,也其实就是记录 images本身(不是中间件)信息的文件;换句话说,它记录了镜像名称、镜像 tag(默认为 latest)、镜像ID等信息。
cat /var/lib/docker/repositories-devicemapper
{"Repositories":{"centos":{"latest":"ce20c473cd8ac1fab6601529ce6a075743f2cf7a8f4cfed2216f8cfcb53bfc4e"}},"ConfirmDefPush":true}
好,有变化的目录我们都查看完了,也发现其中变化的信息,那这时候还有一些目录是未曾变
化的,分别为:
/var/lib/docker/container
/var/lib/docker/tmp
/var/lib/docker/trust
/var/lib/docker/volumes
那,这时候我们把 centos images 跑起来,run container 后看看目录结构会发生什么变化:
docker run -d -it –name centos centos 来运行 centos images
[root@docker-100 docker]# tree /var/lib/docker/
/var/lib/docker/
├── containers
│ └── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052
│ ├── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052-json.log
│ ├── config.json
│ ├── hostconfig.json
│ ├── hostname
│ ├── hosts
│ ├── resolv.conf
│ ├── resolv.conf.hash
│ └── secrets
├── devicemapper
│ ├── devicemapper
│ │ ├── data
│ │ └── metadata
│ ├── metadata
│ │ ├── 168a69b6220279e6d5bd8dafd2edf71434a08e32b60a7060f7a705f64857169d
│ │ ├── 4234bfdd88f8ed2bc4607bd2ebba2d41d61e2693ad0d184e7b05e1b57f8b8b33
│ │ ├── 47d44cb6f252ea4f6aecf8a447972de5d9f9f2e2bec549a2f1d8f92557f4d05a
│ │ ├── 812e9d9d677f15c39277b2edc8f9bc07354c899483409bb07d1c13c2b9c33ec8
│ │ ├── base
│ │ ├── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052
│ │ ├── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052-init
│ │ ├── ce20c473cd8ac1fab6601529ce6a075743f2cf7a8f4cfed2216f8cfcb53bfc4e
│ │ ├── deviceset-metadata
│ │ └── transaction-metadata
│ └── mnt
│ ├── 168a69b6220279e6d5bd8dafd2edf71434a08e32b60a7060f7a705f64857169d
│ ├── 4234bfdd88f8ed2bc4607bd2ebba2d41d61e2693ad0d184e7b05e1b57f8b8b33
│ ├── 47d44cb6f252ea4f6aecf8a447972de5d9f9f2e2bec549a2f1d8f92557f4d05a
│ ├── 812e9d9d677f15c39277b2edc8f9bc07354c899483409bb07d1c13c2b9c33ec8
│ ├── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052
│ ├── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052-init
│ └── ce20c473cd8ac1fab6601529ce6a075743f2cf7a8f4cfed2216f8cfcb53bfc4e
├── graph
│ ├── 168a69b6220279e6d5bd8dafd2edf71434a08e32b60a7060f7a705f64857169d
│ │ ├── json
│ │ ├── layersize
│ │ ├── tar-data.json
│ │ └── tar-data.json.gz.bak
│ ├── 4234bfdd88f8ed2bc4607bd2ebba2d41d61e2693ad0d184e7b05e1b57f8b8b33
│ │ ├── json
│ │ ├── layersize
│ │ └── tar-data.json.gz
│ ├── 47d44cb6f252ea4f6aecf8a447972de5d9f9f2e2bec549a2f1d8f92557f4d05a
│ │ ├── json
│ │ ├── layersize
│ │ └── tar-data.json.gz
│ ├── 812e9d9d677f15c39277b2edc8f9bc07354c899483409bb07d1c13c2b9c33ec8
│ │ ├── json
│ │ ├── layersize
│ │ └── tar-data.json.gz
│ ├── ce20c473cd8ac1fab6601529ce6a075743f2cf7a8f4cfed2216f8cfcb53bfc4e
│ │ ├── json
│ │ ├── layersize
│ │ └── tar-data.json.gz
│ └── _tmp
├── linkgraph.db
├── repositories-devicemapper
├── tmp
├── trust
└── volumes
24 directories, 37 files
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
跟前面对比,有变化的其实是三个文件:
/var/lib/docker/devicemapper/medata
/var/lib/docker/devicemapper/mnt
/var/lib/docker/container
我们先来看 /var/lib/docker/devicemapper/medata/下的文件
[root@docker-100 containers]
/var/lib/docker/devicemapper/metadata/
├── 168a69b6220279e6d5bd8dafd2edf71434a08e32b60a7060f7a705f64857169d
├── 4234bfdd88f8ed2bc4607bd2ebba2d41d61e2693ad0d184e7b05e1b57f8b8b33
├── 47d44cb6f252ea4f6aecf8a447972de5d9f9f2e2bec549a2f1d8f92557f4d05a
├── 812e9d9d677f15c39277b2edc8f9bc07354c899483409bb07d1c13c2b9c33ec8
├── base
├── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052
├── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052-init
├── ce20c473cd8ac1fab6601529ce6a075743f2cf7a8f4cfed2216f8cfcb53bfc4e
├── deviceset-metadata
└── transaction-metadata
0 directories, 10 files
与之前 docker pull images (还未运行容器)时,多了两个文件,那下面两个文件是干嘛的呢,当Docker运行一个从镜像建立的容器,它会在镜像顶部添加一个可读写的层,应用程序可以在这里运行,所以这时候会有这两个文件也不足为奇了,下面来看看新增的两个文件与之前的信息有何不同(该目录下的文件为 images 的描述信息)
├── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052
├── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052-init
一个一个来查看 base 、以及后面的 5 个中间件(包括 images 本身)还有新增的两个文件,发现前面五个文件没变,后面两个(c2adc… 和 c2adc…-init)描述了本身的一些信息。
[root@docker-100 metadata]
{"device_id":1,"size":107374182400,"transaction_id":3,"initialized":true}
[root@docker-100 metadata]
{"device_id":2,"size":107374182400,"transaction_id":4,"initialized":false}
[root@docker-100 metadata]
{"device_id":3,"size":107374182400,"transaction_id":5,"initialized":false}
[root@docker-100 metadata]
{"device_id":5,"size":107374182400,"transaction_id":7,"initialized":false}
[root@docker-100 metadata]
{"device_id":4,"size":107374182400,"transaction_id":6,"initialized":false}
[root@docker-100 metadata]
{"device_id":6,"size":107374182400,"transaction_id":8,"initialized":false}
[root@docker-100 metadata]
{"device_id":7,"size":107374182400,"transaction_id":9,"initialized":false}
[root@docker-100 metadata]
{"device_id":8,"size":107374182400,"transaction_id":10,"initialized":false}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
那我们来看下,发生变化的第二个文件 /var/lib/docker/devicemapper/mnt,它也和 metadata 中的文件一样,只是在该目录下面 新增了两个目录(c2adc… 和 c2adc…-init)
[root@docker-100 mnt]
/var/lib/docker/devicemapper/mnt/
├── 168a69b6220279e6d5bd8dafd2edf71434a08e32b60a7060f7a705f64857169d
├── 4234bfdd88f8ed2bc4607bd2ebba2d41d61e2693ad0d184e7b05e1b57f8b8b33
├── 47d44cb6f252ea4f6aecf8a447972de5d9f9f2e2bec549a2f1d8f92557f4d05a
├── 812e9d9d677f15c39277b2edc8f9bc07354c899483409bb07d1c13c2b9c33ec8
├── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052
├── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052-init
└── ce20c473cd8ac1fab6601529ce6a075743f2cf7a8f4cfed2216f8cfcb53bfc4e
7 directories, 0 files
最后我们来查看发生变化的第三个目录,也就是 /var/lib/docker/container ,容器本身的目录,终于发现了变化:
那这时候我们就可以根据现在的信息推断出,前面两个文件都是用来描述该容器的信息以及数据。
[root@docker-100 containers]# tree /var/lib/docker/containers/
/var/lib/docker/containers/
└── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052
├── c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052-json.log
├── config.json
├── hostconfig.json
├── hostname
├── hosts
├── resolv.conf
├── resolv.conf.hash
└── secrets
2 directories, 7 files
在查看过容器目录 container 发现下面有一个 c2adc…(容器本身)的目录,并且该目录下有许多子文件:
简单cat查看,发现 container log 信息,以及配置文件(需要 cat config.json | Python -mjson.tools 查看),还有 host 及 resolv 等配置。那这时候我们就很清晰的了解到目录的变化。
[root@docker-100 docker]# ls -l containers/c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052/
total 24
-rw-------. 1 root root 0 Dec 12 20:13 c2adc691ad19428e44d655d9daa8573cd71b162e05faaaa824010929089bc052-json.log
-rw-r--r--. 1 root root 2244 Dec 12 20:13 config.json
-rw-r--r--. 1 root root 651 Dec 12 20:13 hostconfig.json
-rw-r--r--. 1 root root 13 Dec 12 20:13 hostname
-rw-r--r--. 1 root root 217 Dec 12 20:13 hosts
-rw-r--r--. 1 root root 51 Dec 12 20:13 resolv.conf
-rw-------. 1 root root 71 Dec 12 20:13 resolv.conf.hash
drwx------. 2 root root 6 Dec 12 20:13 secrets
[root@docker-100 docker]#
如果在这时候删除该容器,就会发现容器的信息全都没了;为什么?因为我们把容器干掉了哇!!! 所涉及的文件:
/var/lib/docker/devicemapper/metadata/c2adc… 及 c2adc…-init 文件
/var/lib/docker/devicemapper/mnt/c2adc… 及 c2adc…-init文件
/var/lib/docker/container/所有文件
总结(每个文件及作用):
1、/var/lib/docker/devicemapper/devicemapper/data #用来存储相关的存储池数据
2、/var/lib/docker/devicemapper/devicemapper/metadata #用来存储相关的元数据。
3、/var/lib/docker/devicemapper/metadata/ #用来存储 device_id、大小、以及传输_id、初始化信息
4、/var/lib/docker/devicemapper/mnt #用来存储挂载信息
5、/var/lib/docker/container/ #用来存储容器信息
6、/var/lib/docker/graph/ #用来存储镜像中间件及本身详细信息和大小 、以及依赖信息
7、/var/lib/docker/repositores-devicemapper #用来存储镜像基本信息
8、/var/lib/docker/tmp #docker临时目录
9、/var/lib/docker/trust #docker信任目录
10、/var/lib/docker/volumes #docker卷目录