1023

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nemo
  • 12,241
  • 3
  • 21
  • 26

31 Answers31

712

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.
Matt
  • 68,711
  • 7
  • 155
  • 158
Air
  • 5,084
  • 5
  • 25
  • 19
  • Ftr: Debian `stretch/sid` uses `devicemapper` too. – dtk Nov 09 '15 at 16:48
  • 2
    Can I see the content inside, by mounting it in some way? – r.v Nov 18 '15 at 14:46
  • 1
    If you set the storage driver after it is already running and has some running containers with images, will it migrate the date on the next restart of the daemon? If not then how to modify the storage driver in this case? – BTR Naidu Apr 12 '16 at 13:54
  • 8
    For MacOS, [see answer below](http://stackoverflow.com/a/37642236/1618202) – ProfNandaa Sep 27 '16 at 18:14
  • Shameless self-plug: you can use the [filepie](https://github.com/marcodiiga/filepie) utility to visualize and navigate through the contents of `docker/aufs` and see how the storage is organized. – Marco A. Nov 02 '16 at 09:56
  • 140
    Do yourself a favor and don't "check defaults". Use `docker info` and find the actual location **specific to your setup**. – Bruno Bronosky May 04 '17 at 15:57
  • I'm seeing overlay2 instead of devicemapper. So i've looked into /var/lib/docker/overlay2 and didn't find anything – Gangadhar Jannu Mar 16 '18 at 13:36
  • I have the JSON image information file at `/var/lib/docker/image/aufs/repositories.json`. Using Docker version 17.09.0-ce with `aufs` driver. – forzagreen May 03 '18 at 08:24
  • CentOS 7.6, docker-ce 18.09.0 uses overlay2 – DeanM Dec 06 '18 at 21:28
  • 11
    This seems to have changed. I am using `Docker for Mac` with 2 images of 1.5 GB each and `/var/lib` has no directory `docker`. – miguelmorin Jan 14 '19 at 10:23
  • on linux this is configured in daemon config file: `/etc/docker/daemon.json` https://docs.docker.com/config/daemon/systemd/ `{ "data-root": "/mnt/docker-data", "storage-driver": "overlay2" }` – bartosz.r Mar 26 '20 at 09:01
  • With specific default path, one can always change the docker storage path in daemon.json with ""data-root": "/var/app/docker/mypath/storage"" – Saurabhcdt Jul 29 '21 at 14:20
325

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

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.

mirosval
  • 6,671
  • 3
  • 32
  • 46
  • 8
    Is this the location for all images (like `ubuntu`, `nginx`), or is this the location for all containers? The original question asks for **images**, not **containers**... – Siu Ching Pong -Asuka Kenji- Aug 05 '17 at 04:49
  • 2
    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. Try this command : docker run --rm -it -v /:/vm-root alpine:edge ls -l /vm-root nad after this : docker run --rm -it -v /:/vm-root alpine:edge ls -l /vm-root/var/lib/docker You are available to list the docker folder from the WM host – user1842947 Mar 22 '18 at 20:01
  • 4
    This seems to have changed. I am using `Docker for Mac` with two images of 1.5 GB each and `~/Library/Containers/Data/com.docker.docker/Data` has no directory `com.docker.driver.amd64-linux` and the only big file is in `vms/0/Docker.raw` with 3.6 GB. – miguelmorin Jan 14 '19 at 10:27
  • 2
    Whether qcow2 or raw is used depends on whether you are at MacOS High Sierra with APFS or below: https://docs.docker.com/docker-for-mac/faqs/#disk-usage – Peter Mar 23 '19 at 15:52
  • 1
    Check size for mac: `du -hd1 ~/Library/Containers/com.docker.docker/Data/` – Efren Aug 30 '19 at 03:32
  • 1
    As for 2.1.0.4 (of Docker Desktop) location is slightly different (extra `data`): `~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw` – Alex Martian Nov 06 '19 at 12:34
  • 1
    A usefull addition to this post is a blog post: https://timonweb.com/posts/getting-path-and-accessing-persistent-volumes-in-docker-for-mac/ – Ian van Wijk Apr 03 '20 at 10:00
139

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

Utkarsh Dubey
  • 703
  • 11
  • 31
Marc Rechté
  • 1,817
  • 1
  • 13
  • 5
  • 4
    This is for RedHat variants. They [chose not to go AUFS as it's not in the mainline kernel](http://developerblog.redhat.com/2014/09/30/overview-storage-scalability-docker/). – Matt Feb 15 '15 at 22:09
  • 16
    Yes, unfortunately, these two lines "(Meta)data file" do not appear in every docker. It depends on the driver used – Orabîg Jul 11 '15 at 07:25
  • @DmitryYudin [mirosval's answer](http://stackoverflow.com/questions/19234831/where-are-docker-images-stored-on-the-host-machine#37642236) works for latest [Docker for Mac](https://docs.docker.com/docker-for-mac/). – Franklin Yu Sep 09 '16 at 18:16
  • 12
    A proper answer is not "This is where it is on MY machine." A proper answer is "Here is **how you find it** on YOUR machine." This is a proper answer. I joined a company with 11 different EBS volumes full of docker images. This answer allowed me to figure out which was the **current** "Root Dir". – Bruno Bronosky May 04 '17 at 15:54
  • 1
    On Mac OS X (at least on Yosemite, which is EOL w.r.t. Docker), `docker info` is very useful, but the output `Docker Root Dir: /var/lib/docker` does not indicate the image storage location (see Mac-specific answer above). – Webel IT Australia - upvoter Feb 21 '18 at 12:21
  • This is out of date for CentOS 7.5. – irritable_phd_syndrome Oct 09 '18 at 11:27
  • This works in Google Cloud - Ubuntu version. I could find the images in /var/lib/docker/overlay2 – Robin Varghese Jun 11 '19 at 07:00
  • 2
    I don't see the said attributes in `docker info` on MacOS Catalina 10.15 – F.S. Dec 30 '19 at 17:48
128

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 .
Phil L.
  • 2,637
  • 1
  • 17
  • 11
  • Docker shuffled things around I believe, so now `boot2docker` results in `command not found` -- thoughts? – slifty Dec 10 '15 at 23:49
  • 17
    Following a new install of Docker on Windows 10, I can confirm that the result of clicking the Docker Quickstart Terminal shortcut for the first time creates a virtual machine (VM) called 'default' (after a couple of unsuccessful starts - keep running it until it works). This 'default' VM can be located within Windows at: `%USERPROFILE%\.docker\machine\machines` (please note the full stop in the path) – AnotherLongUsername Jan 20 '16 at 16:43
  • 6
    In newer releases **boot2docker** is now **docker-machine**. See https://docs.docker.com/machine/migrate-to-machine/ – khylo Apr 12 '16 at 20:29
  • 3
    Is it possible to change that location? – dhblah Apr 14 '16 at 10:11
  • Now that Docker has moved to **docker-machine** I can't locate the image folder on Windows 10. The folder `%USERPROFILE%\.docker` doesn't exist. – Jordan Mack Jun 23 '16 at 00:14
  • 14
    The answer is no longer correct for Windows 10. Instead, see the newer answer from @tristan which references `C:\Users\Public\Documents\Hyper-V\Virtual hard disks\MobyLinuxVM.vhdx` – aaronsteers Oct 29 '16 at 21:24
  • 5
    %USERPROFILE%\.docker is still correct for win7 setups. – RMorrisey Mar 15 '17 at 14:28
  • 1
    This answer is super old, and needs to be updated. -- Docker on Windows is definitely not using VirtualBox (you can see the VM in Hyper-V, which would have to be disabled for VirtualBox to even run...) – BrainSlugs83 Sep 04 '19 at 17:12
77

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.

Tristan
  • 891
  • 6
  • 4
  • 15
    Docker on Windows 10 Anniversary Update puts image files in `C:\ProgramData\docker\windowsfilter` for me. More info: http://stackoverflow.com/a/39971954/188740 – Johnny Oshika Oct 11 '16 at 07:04
  • 1
    'Hyper-V Manager' is the answer ! – Reza Oct 21 '18 at 19:02
  • I don't have Hyper V and I am using Docker Toolbox .. Any idea where the virtual disk will be – S A Jun 23 '20 at 08:39
  • -- I have a file in `C:\Users\UserName\AppData\Local\Docker\wsl\data\ext4.vhdx` 1.6GB (& `\Docker\wsl\distro\ext4.vhdx` 105MB). not sure if thats the image. (Im not using Hyper-V, but WSL 2.) -- (-- I tried many other answers, those folders locations like `var/lib/docker`, `overlay2`, `DockerDesktop`, just either none exist / doesnt contain the image files, in my Window OS. -- Though, `$ docker info` does show `Storage Driver: overlay2`; & `$ docker inspect container_id` does show `"MergedDir": "/var/lib/docker/overlay2/4zxxxxxxpb/merged"`. -- I have no idea why.) – Nor.Z Apr 29 '22 at 15:38
75

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.

liwp
  • 6,746
  • 1
  • 27
  • 39
creack
  • 116,210
  • 12
  • 97
  • 73
60

On Ubuntu you can "play" with images running

sudo baobab /var/lib/docker

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

screenshot showing disk analyzer tool baobab running on /var/lib/docker

test30
  • 3,496
  • 34
  • 26
51

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.

Community
  • 1
  • 1
mbbce
  • 2,245
  • 1
  • 19
  • 31
24

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

   > docker info
   ...
   Docker Root Dir: C:\ProgramData\Docker
   ...
Tormod Haugene
  • 3,538
  • 2
  • 29
  • 47
23

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

0 _
  • 10,524
  • 11
  • 77
  • 109
Sunil Fernandes
  • 239
  • 2
  • 6
  • Yeah, when I did a: `jasper@~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux $ ls -lh | grep Docker -rw-r--r--@ 1 jasper staff 6.3G May 25 19:20 Docker.qcow2` I found the image. But that is not the containers though. Do not see them in this Data directory really.. – rhand May 25 '17 at 16:22
  • 1
    But as stated before you here https://stackoverflow.com/a/37642236/460885 it is inside this image that the containers are located. – rhand May 25 '17 at 16:51
13
sudo docker info | grep -e "Root Dir"
Savrige
  • 3,352
  • 3
  • 32
  • 38
8

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
Community
  • 1
  • 1
Ricardo Martins
  • 5,702
  • 3
  • 40
  • 59
8

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
halfer
  • 19,824
  • 17
  • 99
  • 186
boni
  • 253
  • 4
  • 7
  • 2
    This only moves the Hyper-V machine not the images, the images would still be stored where the VHD location is. – olive_tree Feb 08 '17 at 00:38
  • @olive_tree I'm trying to find the images created by `docker build` command. I'm on a Windows 10 computer. I look in C:\Users\Public\Documents\Hyper-V\Virtual hard disks, but all I see is MobyLinuxVM.vhdx. Where are the actual images stored? – user3731622 Apr 12 '19 at 00:13
8

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"]]
Community
  • 1
  • 1
kenorb
  • 155,785
  • 88
  • 678
  • 743
  • Do you know why when using `docker pull` this does not ask for user password despite the directory `/var/lib/docker` and its subdirectories are only readable/writable by root? I already have my user in docker group, but I wonder how is it possible to download images if only root has access – Edgar Magallon Mar 02 '23 at 02:04
7

For "Docker Desktop", click on docker system tray icon and click "Settings".

enter image description here

On the Advanced tab, you can see the disk image location.

enter image description here

Nishan
  • 3,644
  • 1
  • 32
  • 41
6

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

user1842947
  • 1,047
  • 1
  • 11
  • 16
  • Thanks! This is the only answer that worked for me on Windows 10 with Hyper-v. I was able to clean up the corrupted files under the elusive /var/lib/docker/overlay2 folder. – Ali Cheaito Feb 13 '20 at 21:51
6

use docker inspect container_id
find folder under MergedDir

# example. 
"MergedDir": "/var/lib/docker/overlay2/f40cc2ea8912ec3b32deeef5a1542a132f6e918acb/merged 
madjardi
  • 5,649
  • 2
  • 37
  • 37
5

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.

Chu-Siang Lai
  • 2,658
  • 1
  • 24
  • 21
5

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

AlessioX
  • 3,167
  • 6
  • 24
  • 40
omasoud
  • 411
  • 5
  • 11
5

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.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Arif A.
  • 933
  • 8
  • 14
4

check for the docker folder in /var/lib

the images are stored at below location:

/var/lib/docker/image/overlay2/imagedb/content
CDspace
  • 2,639
  • 18
  • 30
  • 36
Chandra Pal
  • 239
  • 2
  • 2
  • 6
    this has only sha256 folder – toto' Feb 21 '19 at 19:10
  • 1
    I think you meant to simply: `/var/lib/docker/image/overlay2/`. Also note that this is the case due to the fact that your Docker engine is using `overlay2` as the Storage Driver. – Guy Avraham Apr 28 '20 at 11:31
  • 1
    @toto' If you navigate inside your sha256 folder you'll see the hashed keys of your images. To identify exactly which image you're looking for, simply `docker image ls -a`. This essentially gives you the first 48 bits of the SHA256 hash key mapped to the repo and tags you've assigned to the particular image. – Ari May 28 '22 at 21:50
4

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,

Overlay Filesystem

Nick Dong
  • 3,638
  • 8
  • 47
  • 84
3

Environment: Windows 10 Pro, docker desktop 2.0.3.0 edge

right-click docker icon in system tray, select settings - advanced :

Disk image location (editable via the browser) :

C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\DockerDesktop.vhdx

(it's there - Documents directory is hidden)

theRiley
  • 1,077
  • 13
  • 16
  • Is C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\DockerDesktop.vhdx the image created by `docker build` command? – user3731622 Apr 12 '19 at 19:42
2

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
eddygeek
  • 4,236
  • 3
  • 25
  • 32
2

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.

shanmuga raja
  • 685
  • 6
  • 19
1

In 2021 on macOS the only possible solution is accessing Docker VM with bash and then see it's local structure:

  1. docker run -ti --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh
  2. cd /var/lib/docker/

You're welcome!

Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
1

Use docker info command to get the host settings of the docker including its storage path.

To get only the root path for the docker storage you may use:

docker info | grep 'Docker Root Dir:' | cut -d':' -f2 | sed 's/^ *//g'

That gives for the default Ubuntu 22.04 and docker --version = Docker version 20.10.17, build 100c701 installation the path:

/var/lib/docker

listing the content of that directory with sizes by the command:

du -h -d 1 .

gives results (other directories):

444K    ./buildkit
4,0K    ./containers
4,0K    ./runtimes
16K     ./plugins
4,0K    ./trust
4,0K    ./tmp
100K    ./network
22M     ./image
2,0G    ./volumes
4,0K    ./swarm
9,0G    ./overlay2

To get docker root path suffixed with one of the directory name's you may add another sed at the end sed 's/$/\/image/g' for suffixing with the /image

command:

docker info | grep 'Docker Root Dir:' | cut -d':' -f2 | sed 's/^ *//g' | sed 's/$/\/image/g'

gives:

/var/lib/docker/image

command:

docker info | grep 'Docker Root Dir:' | cut -d':' -f2 | sed 's/^ *//g' | sed 's/$/\/overlay2/g'

gives:

/var/lib/docker/overlay2

Although names of the directories may seem self-explanatory the content of the images isn't stored in the image directory (22M size) but rather the information of the images. /var/lib/docker/image/overlay2 in my case and especially the /var/lib/docker/image/overlay2/repositories.json file that has the names of the images and corresponding to them data about the overlay2 layers.

The actual data of the images (and their layers) is stored in /var/lib/docker/overlay2 (9,0G size)

Please note that the overlay2 where the heavy data of the images is stored is a layerying system used by the docker but that layering system is one of many that docker may use (now or in the future). Therefore basing on the hard-coded paths may be fragile.

Especially if your intention is to expport/save the images into file you should look for the dedicated commands:

What is the difference between save and export in Docker?

With the command from the question as above you may even save all of your images into one file, compress it and then import them elsewhere by a single command.

If you want stick to the docker paths ie for creating backups I would recommend always use the root path for eg:

/var/lib/docker

generated by the docker info command especially you may have also important data inside:

/var/lib/docker/volumes

that is required by for eg. by the image of the database that uses a volume to persist the data.

Jimmix
  • 5,644
  • 6
  • 44
  • 71
0

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

Dhanuka
  • 2,826
  • 5
  • 27
  • 38
0

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.

axelrose
  • 556
  • 5
  • 17
0

Images are stored inside /var/lib/docker and then under applicable storage driver directory.

Storage driver, being used, can be determined by executing docker info command.

Anshul Singhal
  • 1,983
  • 20
  • 25
0

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
vulcan raven
  • 32,612
  • 11
  • 57
  • 93
  • On CentOS I had to use `DOCKER_ROOT_DIR="$(sudo docker info 2>&1 | grep -oP '(?<=Data loop file: ).*')"`, but in the end it is a file, not a directory – HairOfTheDog Oct 22 '19 at 02:38
  • Are you sure it is not a directory? For me, `sudo ls "$(docker info 2>&1 | grep -oP '(?<=^Docker Root Dir: ).*')"` list the contents of this directory. – vulcan raven Oct 26 '19 at 10:21