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
?
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
?
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 metadataWhen 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
UPDATE (Courtesy of mmorin):
As of Jan 15 2019 it seems there is only this file:
~/Library/Containers/com.docker.docker/Data/vms/0/Docker.raw
that contains the Docker Disk and all the images and containers within it.
this was the old way of doing, now it has changed. Disregard this answer as of 2019
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 .
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
Expanding on Tristan's answer, in Windows with Hyper-V you can move the image with these steps from matthuisman:
In Windows 10,
- Stop docker etc
- Type "Hyper-V Manager" in task-bar search box and run it.
- Select your PC in the left hand pane (Mine is called DESKTOP-CBP**)
- Right click on the correct virtual machine (Mine is called MobyLinuxVM)
- Select "Turn off" (If it is running)
- Right click on it again and select "Move"
- Follow the prompts
Use docker info
command to display system-wide information and the location may vary.
Depending on the storage driver in use, additional information can be shown, such as pool name, data file, metadata file, data space used, total data space, metadata space used, and total metadata space.
The data file is where the images are stored and the metadata file is where the meta data regarding those images are stored. When run for the first time Docker allocates a certain amount of data space and meta data space from the space available on the volume where
/var/lib/docker
is mounted.
Here is the example on Ubuntu (check Root Dir):
$ docker info
...
Server Version: 18.06.1-ce
Storage Driver: aufs
Root Dir: /var/snap/docker/common/var-lib-docker/aufs
...
Docker Root Dir: /var/snap/docker/common/var-lib-docker
...
And here is the example on Travis CI (see Docker Root Dir):
$ docker info
Server Version: 17.09.0-ce
Storage Driver: overlay2
Backing Filesystem: extfs
...
Docker Root Dir: /var/lib/docker
...
You can use --format
parameter to extract that information into a single file, e.g.
$ docker info --format '{{.DriverStatus}}'
[[Root Dir /var/snap/docker/common/var-lib-docker/aufs] [Backing Filesystem extfs] [Dirs 265] [Dirperm1 Supported true]]
or:
$ docker info --format '{{json .DriverStatus}}'
[["Root Dir","/var/snap/docker/common/var-lib-docker/aufs"],["Backing Filesystem","extfs"],["Dirs","265"],["Dirperm1 Supported","true"]]
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 VM host
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.
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.
In Windows 2016, docker (DockerMsftProvider) uses the folder "windowsfilter" under docker root
>docker info
...
Storage Driver: windowsfilter
...
Docker Root Dir: C:\ProgramData\docker
...
It uses the "tmp" folder under docker root to download the files and it deletes the files after extracting the downloaded files to "windowsfilter" folder.
ENV
OS: fedora 29 x86_64 workstation
Docker:
[user@localhost ~]$ docker --version
Docker version 19.03.5, build 633a0ea838
Image info: "DockerVersion": "18.09.7"
The images should stored in /var/lib/docker/overlay2
by default.
MY EXAMPLE
Show images:
[user@localhost ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
neo4j latest 8ed7463b8476 12 months ago 548MB
hello-world latest fce289e99eb9 2 years ago 1.84kB
The image size is 548M.
See the image information of 8ed7463b8476
.
[user@localhost ~]$ docker image inspect 8ed7463b8476
... ... ... ...
"DockerVersion": "18.09.7",
... ... ... ...
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2
/66dc24704d7ea5f1a5dee0bf4a5297cb78bcbd0d4b36206b8cca62cd4de7f2b1/diff:
/var/lib/docker/overlay2
/5ab91cf721359d43d01038233d397fd9ed1c4b3857c0c7d9a2dd7f2ac5eccad0/diff:
/var/lib/docker/overlay2
/e82fdf7ee3e37db0a11d9ca309245ae852425d24d6f5d3313dcf604cdddb397b/diff:
/var/lib/docker/overlay2
/9394543085d467010d0468fffb388e5616a89e2cf16c1c2b7b31aee4e542ae69/diff:
/var/lib/docker/overlay2
/c7c7a16e3dbaeea1a3a3b0bbca39f34f08f6b8ab15d753e6e68f9851c80d95b4/diff:
/var/lib/docker/overlay2
/3b470afdf8939b45159f3171f0bef2a27085b4b980e09f0c666fbdc58b944d97/diff:
/var/lib/docker/overlay2
/463ba63f79eb6b2f5466e7b71041bc346a8e9c4ebddd34d23422c719824a2340/diff",
... ... ... ...
Let's see the size of these folders.
[user@localhost ~]$ sudo du -sh /var/lib/docker/overlay2/66dc24704d7ea5f1a5dee0bf4a5297cb78bcbd0d4b36206b8cca62cd4de7f2b1
141M /var/lib/docker/overlay2/66dc24704d7ea5f1a5dee0bf4a5297cb78bcbd0d4b36206b8cca62cd4de7f2b1
[user@localhost ~]$ sudo du -sh /var/lib/docker/overlay2/5ab91cf721359d43d01038233d397fd9ed1c4b3857c0c7d9a2dd7f2ac5eccad0/
28K /var/lib/docker/overlay2/5ab91cf721359d43d01038233d397fd9ed1c4b3857c0c7d9a2dd7f2ac5eccad0/
[user@localhost ~]$ sudo du -sh /var/lib/docker/overlay2/e82fdf7ee3e37db0a11d9ca309245ae852425d24d6f5d3313dcf604cdddb397b/
100K /var/lib/docker/overlay2/e82fdf7ee3e37db0a11d9ca309245ae852425d24d6f5d3313dcf604cdddb397b/
[user@localhost ~]$ sudo du -sh /var/lib/docker/overlay2/9394543085d467010d0468fffb388e5616a89e2cf16c1c2b7b31aee4e542ae69/
310M /var/lib/docker/overlay2/9394543085d467010d0468fffb388e5616a89e2cf16c1c2b7b31aee4e542ae69/
[user@localhost ~]$ sudo du -sh /var/lib/docker/overlay2/c7c7a16e3dbaeea1a3a3b0bbca39f34f08f6b8ab15d753e6e68f9851c80d95b4/
36K /var/lib/docker/overlay2/c7c7a16e3dbaeea1a3a3b0bbca39f34f08f6b8ab15d753e6e68f9851c80d95b4/
[user@localhost ~]$ sudo du -sh /var/lib/docker/overlay2/3b470afdf8939b45159f3171f0bef2a27085b4b980e09f0c666fbdc58b944d97/
9.5M /var/lib/docker/overlay2/3b470afdf8939b45159f3171f0bef2a27085b4b980e09f0c666fbdc58b944d97/
[user@localhost ~]$ sudo du -sh /var/lib/docker/overlay2/463ba63f79eb6b2f5466e7b71041bc346a8e9c4ebddd34d23422c719824a2340/
76M /var/lib/docker/overlay2/463ba63f79eb6b2f5466e7b71041bc346a8e9c4ebddd34d23422c719824a2340/
We can see the size that is close to 548M.
We also can save image to an output file.
[user@localhost ~]$ docker save -o neo4j.image.tar 8ed7463b8476
[user@localhost ~]$ du -sh neo4j.image.tar
528M neo4j.image.tar
We can extract the package file and check the sizes of files in the package.
[user@localhost neo4j.image]$ du -sh *
16K 2f0dd5fb60a940719a3e781133611cc64c2acded03bd47e04b0997fd0c1dae50
8.7M 73819037a38eabeb7c622533e4058c84f5ff106475a1aba78a278f8b36c172f7
309M 8d31d715b324a2ae3ccb1577e981d492f40e34db6371f0858da925ef02b5762e
12K 8ed7463b84760f09b1b86a732ee6f295baaadffe72ce4fdb7ad306fe5e096bbb.json
36K 966e726ff1d9be9dca68014cda6f1ecf974365c553b82ea3834fff5d73ea593e
70M a32776b9621e916e8714389b1037bf47253a2d3d1c806ad515623d2150c92485
60K d82868a318b95466f213136f81cd7258518744da72f46ca51b04b35f2351f46a
16K e62169d79fab44bebb0a455b01af5f636bace7673a1d38fc092daad77d51cd0e
141M fe8014622f7933e178b9005deffda3eb4828703eb7eca93b5485232930e3916b
4.0K manifest.json
We also can archive the folder /var/lib/docker/overlay2/
to compare the size of the package to image files. The size is close to the image size either.
More helpful readings:
docker image - merged/diff/work/LowerDir components of GraphDriver,
Where are Docker Images Stored? Docker Container Paths Explained,
I couldn't resolve the question with Docker version 18.09 on macos using the above answers and tried again.
The only actual solution for me was using this docker-compose.yml
configuration:
version: '3.7'
...
services:
demo-service:
volumes:
- data-volume:/var/tmp/container-volume
volumes:
data-volume:
driver: local
driver_opts:
type: none
o: bind
device: /tmp/host-volume
After launching with docker-compose up
I finally had /tmp/host-volume
from macos shared as writeable volume from within the container:
> docker exec -it 1234 /bin/bash
bash-4.4$ df
Filesystem 1K-blocks Used Available Use% Mounted on
...
osxfs 488347692 464780044 21836472 96% /var/tmp/container-volume
Hope this helps others too.
If anyone need it for scripting purposes, here is a one-line solution.
In POSIX shell, with PCRE enabled grep
, try:
DOCKER_ROOT_DIR="$(docker info 2>&1 | grep -oP '(?<=^Docker Root Dir: ).*')"
In PowerShell:
$DOCKER_ROOT_DIR="$(docker info 2>&1 | foreach {if($_ -match "Docker Root Dir"){$_.TrimStart("Docker Root Dir: ")}})"
Note, when on Windows 10 (as of 10.0.18999.1
), in default configurations, it returns:
C:\ProgramData\Docker
in "Windows containers" mode/var/lib/docker
, in "Linux containers" mode