Where are Docker images stored on the host machine

2018-12-31 18:01发布

I managed to find the containers under directory /var/lib/docker/containers, but I can't find the images.

What are the directories and files under /var/lib/docker?

19条回答
与风俱净
2楼-- · 2018-12-31 18:41

In the special case of Mac OS X or Windows, using boot2docker, your Docker images are stored within a VirtualBox VM managed by boot2docker.

This VM will be stored in normal place of VirtualBox images:

      OS X: ~/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:

docker build -t webapp --rm=true --force-rm=true .

instead of:

docker build -t webapp .
查看更多
深知你不懂我心
3楼-- · 2018-12-31 18:41

If you keep in mind that Docker is still running in a VM, the system paths are relative to the VM and not from the Mac Osx system. As it says all is contained in a VM file :

/Users/MyUserName/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2

Try to run Alpine image with this volume option and the ls command you are able to list the VM host:

docker run --rm -it -v /:/vm-root alpine:edge ls -l /vm-root

After this just try :

docker run --rm -it -v /:/vm-root alpine:edge ls -l /vm-root/var/lib/docker

Now, you are able to list the docker folder from the WM host

查看更多
闭嘴吧你
4楼-- · 2018-12-31 18:46

I can answer this question only for Ubuntu users:

The root directory of docker can be found when you run the command docker info

Docker directory will be given in this line: "Docker Root Dir: /var/lib/docker"

About the docker images, they are stored inside the docker directory: /var/lib/docker/aufs/diff/

Remember these things are not same in all version of docker. Currently, I am using 1.12.3.

查看更多
回忆,回不去的记忆
5楼-- · 2018-12-31 18:47

On Fedora, Docker uses LVM for storage if available. On my system docker info shows:

Storage Driver: devicemapper
 Pool Name: vg01-docker--pool
 Pool Blocksize: 524.3 kB
 Base Device Size: 10.74 GB
 Backing Filesystem: xfs
 Data file:
 Metadata file:
 Data Space Used: 9.622 GB
 ...

In that case, to increase storage, you will have to use LVM command line tools or compatible partition managers like blivet.

查看更多
闭嘴吧你
6楼-- · 2018-12-31 18:53

The images are stored in /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.

When you docker run an image. AUFS will 'merge' all layers into one usable file system.

查看更多
春风洒进眼中
7楼-- · 2018-12-31 18:53

As answered here, if you're on Mac, it is located at

/Users/MyUserName/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2
查看更多
登录 后发表回答