Where are Docker images stored on the host machine?

后端 未结 29 1705
逝去的感伤
逝去的感伤 2020-11-22 06:28

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

相关标签:
29条回答
  • 2020-11-22 07:08

    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.

    0 讨论(0)
  • 2020-11-22 07:09

    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.

    0 讨论(0)
  • 2020-11-22 07:10

    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.
    0 讨论(0)
  • 2020-11-22 07:10

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

    0 讨论(0)
  • 2020-11-22 07:11

    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
    0 讨论(0)
提交回复
热议问题