Where are Docker images stored on the host machine

2018-12-31 18:12发布

问题:

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?

回答1:

The contents of the /var/lib/docker directory vary depending on the driver Docker is using for storage.

By default this will be aufs but can fall back to overlay, overlay2, btrfs, devicemapper or zfs depending on your kernel support. In most places this will be aufs but the RedHats went with devicemapper.

You can manually set the storage driver with the -s or --storage-driver= option to the Docker daemon.

  • /var/lib/docker/{driver-name} will contain the driver specific storage for contents of the images.
  • /var/lib/docker/graph/<id> now only contains metadata about the image, in the json and layersize files.

In the case of aufs:

  • /var/lib/docker/aufs/diff/<id> has the file contents of the images.
  • /var/lib/docker/repositories-aufs is a JSON file containing local image information. This can be viewed with the command docker images.

In the case of devicemapper:

  • /var/lib/docker/devicemapper/devicemapper/data stores the images
  • /var/lib/docker/devicemapper/devicemapper/metadata the metadata
  • Note these files are thin provisioned \"sparse\" files so aren\'t as big as they seem.


回答2:

When using Docker for Mac Application, it appears that the containers are stored within the VM located at:

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


回答3:

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 .


回答4:

Actually, Docker images are stored in two files as shown by following command

$ docker info

Data file: /var/lib/docker/devicemapper/devicemapper/data

Metadata file: /var/lib/docker/devicemapper/devicemapper/metadata



回答5:

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.



回答6:

On the newly released \'Docker for Windows\', which uses Hyper-V, data is located in the Docker virtual hard disk:

C:\\Users\\Public\\Documents\\Hyper-V\\Virtual hard disks\\MobyLinuxVM.vhdx

You can also open the \'Hyper-V Manager\' for access to the Docker / MobyLinuxVM.



回答7:

For someone who is using Docker toolbox (that uses docker-machine), the answers concerning boot2docker on Mac OS X is not valid. The docker-machine VM is called \"default\" and it exists in the /Users/<username>/.docker/machine/machines/default/ directory.



回答8:

On Ubuntu you can \"play\" with images running

sudo baobab /var/lib/docker

Actually, images are stored within /var/lib/docker/aufs/diff

\"screenshot



回答9:

In Docker for Windows (native Windows) the default container storage is at:

   > docker info
   ...
   Docker Root Dir: C:\\ProgramData\\Docker
   ...


回答10:

If you are using Docker for MAC (not boot2docker) then the location is /Users/<</>UserName></>/Library/Containers/com.docker.docker/Data/



回答11:

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


回答12:

Expanding on Tristan\'s answer, in Windows with Hyper-V you can move the image with these steps from matthuisman:

In Windows 10,

  1. Stop docker etc
  2. Type \"Hyper-V Manager\" in task-bar search box and run it.
  3. Select your PC in the left hand pane (Mine is called DESKTOP-CBP**)
  4. Right click on the correct virtual machine (Mine is called MobyLinuxVM)
  5. Select \"Turn off\" (If it is running)
  6. Right click on it again and select \"Move\"
  7. Follow the prompts


回答13:

I use the boot2docker for Docker on Mac OSX, so the images is stored into the /Users/<USERNAME>/VirtualBox VMs/boot2docker-vm/boot2docker-vm.vmdk.



回答14:

In Docker for Windows, the logs are here: %USERPROFILE%\\AppData\\Local\\Docker



回答15:

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



回答16:

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.



回答17:

check for the docker folder in /var/lib

the images are stored at below location:

/var/lib/docker/image/overlay2/imagedb/content


回答18:

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.



回答19:

On Debian Unstable/Sid,

docker info to find system-wide information.

images are stored at /var/lib/docker/image/overlay2/imagedb/content and

containers are stored at /var/lib/docker/containers

docker version 18.06.0-ce, API version 1.38