本文翻译自:Where are Docker images stored on the host machine?
I managed to find the containers under directory /var/lib/docker/containers
, but I can't find the images. 我设法在目录/var/lib/docker/containers
containers下找到了容器,但是找不到图像。
What are the directories and files under /var/lib/docker
? /var/lib/docker
下的目录和文件是什么?
#1楼
参考:https://stackoom.com/question/1IhrD/Docker映像存储在主机上的什么位置
#2楼
The images are stored in /var/lib/docker/graph/<id>/layer
. 图像存储在/var/lib/docker/graph/<id>/layer
。
Note that images are just diffs from the parent image. 请注意,图像只是与父图像的差异。 The parent ID is stored with the image's metadata /var/lib/docker/graph/<id>/json
. 父ID与图像的元数据/var/lib/docker/graph/<id>/json
存储在一起。
When you docker run
an image. 当您docker run
映像时。 AUFS will 'merge' all layers into one usable file system. AUFS将所有层“合并”到一个可用的文件系统中。
#3楼
On Ubuntu you can "play" with images running 在Ubuntu上,您可以“播放”正在运行的图像
sudo baobab /var/lib/docker
Actually, images are stored within /var/lib/docker/aufs/diff
实际上,图像存储在/var/lib/docker/aufs/diff
#4楼
In the special case of Mac OS X or Windows, using boot2docker, your Docker images are stored within a VirtualBox VM managed by boot2docker. 在Mac OS X或Windows的特殊情况下,使用boot2docker,则将Docker映像存储在由boot2docker管理的VirtualBox VM中。
This VM will be stored in normal place of VirtualBox images: 该虚拟机将存储在VirtualBox映像的常规位置:
OS X: ~/VirtualBox VMs/boot2docker-vm
OS X: ~/VirtualBox VMs/boot2docker-vm
Windows: %USERPROFILE%/VirtualBox VMs/boot2docker-vm
Windows: %USERPROFILE%/VirtualBox VMs/boot2docker-vm
You can reset it by running (WARNING: This will destroy all images you've built and downloaded so far): 您可以通过运行来重置它(警告:这将破坏您到目前为止构建并下载的所有图像):
boot2docker down
boot2docker destroy
boot2docker init
boot2docker up
This is especially useful if you kept tons of intermediate images when building / debugging a build without the useful --rm options, I quote them here for reference: Use: 如果在构建/调试构建时没有大量有用的--rm选项的情况下保留了大量中间映像,则此功能特别有用,在此引用以供参考:使用:
docker build -t webapp --rm=true --force-rm=true .
instead of: 代替:
docker build -t webapp .
#5楼
The contents of the /var/lib/docker
directory vary depending on the driver Docker is using for storage . /var/lib/docker
目录的内容根据Docker用于存储的驱动程序而有所不同。
By default this will be aufs
but can fall back to overlay
, overlay2
, btrfs
, devicemapper
or zfs
depending on your kernel support. 默认情况下,它将是aufs
但根据您的内核支持,可以回落到overlay
, overlay2
, btrfs
, devicemapper
或zfs
。 In most places this will be aufs
but the RedHats went with devicemapper
. 在大多数地方,这将是aufs
但是RedHats与devicemapper
一起使用 。
You can manually set the storage driver with the -s
or --storage-driver=
option to the Docker daemon . 您可以使用Docker守护程序的-s
或--storage-driver=
选项手动设置存储驱动程序 。
-
/var/lib/docker/{driver-name}
will contain the driver specific storage for contents of the images./var/lib/docker/{driver-name}
将包含驱动程序特定的图像内容存储。 -
/var/lib/docker/graph/<id>
now only contains metadata about the image, in thejson
andlayersize
files./var/lib/docker/graph/<id>
现在仅在json
和layersize
文件中包含有关图像的元数据。
In the case of aufs
: 对于aufs
:
-
/var/lib/docker/aufs/diff/<id>
has the file contents of the images./var/lib/docker/aufs/diff/<id>
具有图像的文件内容。 -
/var/lib/docker/repositories-aufs
is a JSON file containing local image information./var/lib/docker/repositories-aufs
是一个包含本地图像信息的JSON文件。 This can be viewed with the commanddocker images
. 可以使用docker images
命令查看。
In the case of devicemapper
: 对于devicemapper
:
-
/var/lib/docker/devicemapper/devicemapper/data
stores the images/var/lib/docker/devicemapper/devicemapper/data
存储映像 -
/var/lib/docker/devicemapper/devicemapper/metadata
the metadata/var/lib/docker/devicemapper/devicemapper/metadata
元数据 - Note these files are thin provisioned "sparse" files so aren't as big as they seem. 请注意,这些文件是精简配置的“稀疏”文件,因此没有看起来那么大。
#6楼
Actually, Docker images are stored in two files as shown by following command 实际上,Docker映像存储在两个文件中,如以下命令所示
$ docker info
Data file:
/var/lib/docker/devicemapper/devicemapper/data
数据文件:/var/lib/docker/devicemapper/devicemapper/data
Metadata file:
/var/lib/docker/devicemapper/devicemapper/metadata
元数据文件:/var/lib/docker/devicemapper/devicemapper/metadata