添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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 ?

Best to state specifics of operating system in the question title and/or questions statement in such cases. Two good answers were provided for linux and macOS (Mac OS X). Webel IT Australia - upvoter Feb 21 '18 at 12:14

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.
  • 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 Do yourself a favor and don't "check defaults". Use docker info and find the actual location specific to your setup . Bruno Bronosky May 4 '17 at 15:57 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 at 10:23

    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.

    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 5 '17 at 4:49 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 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 at 10:27 Whether qcow2 or raw is used depends on whether you are at MacOS High Sierra with APFS or below: docs.docker.com/docker-for-mac/faqs/#disk-usage – Peter Mar 23 at 15:52

    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:

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

    instead of:

    docker build -t webapp .
                    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
                    In newer releases boot2docker is now docker-machine. See docs.docker.com/machine/migrate-to-machine
                        – khylo
                    Apr 12 '16 at 20:29
                    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
                    This is for RedHat variants. They chose not to go AUFS as it's not in the mainline kernel.
                        – Matt
                    Feb 15 '15 at 22:09
                    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 7:25
                    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 4 '17 at 15:54
                    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
    

    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.

    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.

    Docker on Windows 10 Anniversary Update puts image files in C:\ProgramData\docker\windowsfilter for me. More info: stackoverflow.com/a/39971954/188740 – Johnny Oshika Oct 11 '16 at 7:04 Nice indeed. On Mac DaisyDisk is similar (wheel display), GrandPerspective also useful (rectangles). – Webel IT Australia - upvoter Feb 21 '18 at 12:44 $docker images -a yields around 1 gig of images, while disk.vmdk in ~/.docker is around 20 gigs. How come? – Grav Apr 29 '16 at 11:28 @Grav: The virtual machine allocates 20 gigs for future use, but only uses 1 gig for images. – primavera133 Jun 10 '16 at 7:27 I ran the docker build command & I don't see a file which I think is the image file. I see some folders and some text files (e.g. service.txt). What type of file & with what file extension does the docker build create? – user3731622 Apr 12 at 0:08 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 But as stated before you here stackoverflow.com/a/37642236/460885 it is inside this image that the containers are located. – rhand May 25 '17 at 16:51

    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
  • This only moves the Hyper-V machine not the images, the images would still be stored where the VHD location is. – olive_tree Feb 8 '17 at 0: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 at 0:13

    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.

    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

    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]]
    
    $ docker info --format '{{json .DriverStatus}}'
    [["Root Dir","/var/snap/docker/common/var-lib-docker/aufs"],["Backing Filesystem","extfs"],["Dirs","265"],["Dirperm1 Supported","true"]]
    

    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)

    Is C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\DockerDesktop.vhdx the image created by docker build command? – user3731622 Apr 12 at 19:42

    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.

    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

    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.

    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.

    This is still strange to me, because now it leads to the question. Where is my machine's local Docker image registry?

    Nevertheless, I definitely think this info is worth sharing as an answer.

    Haha TBH I think this is at most a comment. Would be a great comment though! – Mong H. Ng Jul 27 at 19:25

    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
  • 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 at 2: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 at 10:21 site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required. rev 2019.12.4.35542