从官方库pull一个镜像:Docker pull ubuntu:14.04
一、在image文件夹中寻找
1.找到镜像库的文件
首先看repositories.json中的数据
root@ubuntu:/var/lib/docker#cat /var/lib/docker/image/aufs/repositories.json | Python -mjson.tool
{
"Repositories": {
"ubuntu": { "ubuntu:14.04 ":"sha256:4a2820e686c449bc943eab8492df4b4eb7f7e8fabda5258d7bc551fec5790436", "ubuntu@sha256:5faf6cb681da2be979a177b60d8c18497f962e3d82268c49db6c74008d0c294d ":"sha256:4a2820e686c449bc943eab8492df4b4eb7f7e8fabda5258d7bc551fec5790436"
}
}
}
看看,是不是正好和docker images的内容一致呢
root@ubuntu:/var/lib/docker#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 14.04 4a2820e686c4 3 weeks ago 188 MB
2.找到镜像描述文件
/var/lib/docker/image/aufs/imagedb/content/sha256/4a2820e686c449bc943eab8492df4b4eb7f7e8fabda5258d7bc551fec5790436
是一个json文件我们只截取了部分:
"rootfs":{
"type": "layers",
"diff_ids": [ "sha256:9669d6b7338336d92ca8e8e5bb90a4a35a934d1c94017322bef35a838615b4ea", "sha256:f5cfc06b640d49f4e5b0778531394ed4819d8824c46cbc21481f5531db35d970", "sha256:768dcfe5d05fd2355facaacaf64a45e84ac4c6b895f335ee02f322a35e912d80", "sha256:d0757a6730d0f8242d131bdb86df046fbd5eb6e3a04328aa10e8881166101a94", "sha256:d649a240e4537a905c43c0f9fd7bfa3f3cbe693b963e838eb6e84065b57aae3d"
]
}
3.找到镜像文件的layerdb
root@ubuntu:/var/lib/docker#ls /var/lib/docker/image/aufs/layerdb/sha256
76f1e34d1d2f369222db0aababcfe88a86e7773289ee479aa8a37db2dbc1ae78
7bb5a611d10e491eda648224aeb1466d7e7c99b4dc73c30acf01f303159e7405
9669d6b7338336d92ca8e8e5bb90a4a35a934d1c94017322bef35a838615b4ea
c872fbb3ed98d37a6abeebcfa16316bde7adafafabb8c7ff66a1ba53aa29f0bc
ddc772e5acb244ff1a1ddc32c6fbe5687b68c26090ce85e1855022ac6afcefbc
查看文件夹中文件
root@ubuntu:/var/lib/docker# ls /var/lib/docker/image/aufs/layerdb/sha256/9669d6b7338336d92ca8e8e5bb90a4a35a934d1c94017322bef35a838615b4ea/
cache-id diff size tar-split.json.gz
查看cache-id中内容:
b1c8bba6bd247accbc8082a4c46aa129e2b6489bd9bffe08387e50b43a08e1cd
二、在aufs文件夹中寻找
cache-id中数据对应aufs/diff文件夹下一个文件
root@ubuntu:/var/lib/docker#ls /var/lib/docker/aufs/diff
045a5f72741ab97228e00f1c8bd7d67b682e12c30def9efec769188e1deb9a56
8444bf1d9f50bf52f649d6e27d94a1fad34e7022e1ae27396b02cafaeb4d37bc
b1c8bba6bd247accbc8082a4c46aa129e2b6489bd9bffe08387e50b43a08e1cd
caba5c4f6a8438d54f4045d06afe9d06ad6c44d7db5bf355d36a18c0fd29d5d3
d04b500544d2efcb8e7e5feb8d37c405360fc9807f272c93eb3fd8cd735a13c5
我们看一下b1c8bba6bd247accbc8082a4c46aa129e2b6489bd9bffe08387e50b43a08e1cd中内容
root@ubuntu:/var/lib/docker# ls/var/lib/docker/aufs/diff/b1c8bba6bd247accbc8082a4c46aa129e2b6489bd9bffe08387e50b43a08e1cd/
bin dev home lib64 mnt proc run srv tmp var boot etc lib media opt root sbin sys usr
上面的逻辑不严谨,仅仅记录自己寻找daocker镜像存储的位置的过程。旨在寻找镜像id和aufs文件夹下的镜像文件之间的联系。
ubuntu16.04中的docker使用的是aufs文件系统,可以通过了解aufs文件系统来了解镜像描述文件和真正的镜像存储位置的关联。