Где docker хранит образы windows

Docker has become an essential tool in the world of software development and deployment, enabling developers to package applications into containers for consistency across various environments. However, understanding how Docker works requires knowing where Docker stores its images and containers on your system. In this article, we’ll break down the storage of Docker images, making it easy to understand where these files are stored and how to manage them.

#Docker images overview

A Docker image is a lightweight, standalone, executable package that includes everything needed to run software, service, runtime, libraries, and settings. Images are fundamental in Docker because they provide a repeatable and consistent environment for your applications.

#Images and containers

Docker images are different from containers. A Docker image is essentially a blueprint that defines how a container should be created, while a container is the runtime instance of that image.

Now, let’s explore the storage locations of Docker images.

Ready to supercharge your Docker infrastructure? Scale effortlessly and enjoy flexible storage with Cherry Servers bare metal or virtual servers. Eliminate infrastructure headaches with free 24/7 technical support, pay-as-you-go pricing, and global availability.

#Default location on Linux

When you install Docker on Linux, the default location for storing Docker images is under /var/lib/docker. This directory holds not only your images but also your containers, volumes, and other data Docker uses to function.

Within this directory, you’ll find subdirectories like overlay2 (or sometimes aufs, depending on your Docker setup). This is where Docker stores image layers, and each layer is a read-only file system.

Here’s an example of how you can view the images Docker is storing:

#List docker images

Use the following command to list all Docker images currently stored on your system:

#View storage backend

The storage backend is important for understanding the layout of the Docker image files. Common backend drivers are overlay2, zfs, and btrfs. Run the following command to see which storage driver Docker is using:

$ docker info | grep Storage
Storage Driver: btrfs

Docker organizes images in layers, where each layer represents a different file system change (like installing a package or adding a file). These layers are stacked on top of each other using the storage driver to form a complete image.

Also read: How to Update a Docker Image

#Default location on windows and macOS

On Windows and macOS, Docker runs inside a virtual machine due to the way Docker utilizes Linux features. This means the image storage is a bit different from Linux, but the general concept remains the same.

For Windows, Docker Desktop stores images in the following path:

C:\ProgramData\DockerDesktop\

For macOS, Docker Desktop stores images within the internal VM under the directory:

/Users/<your-username>/Library/Containers/com.docker.docker/Data/vms/

In both cases, the actual image files reside within the Docker virtual machine, and you can interact with them via Docker’s command-line interface.

#Managing docker storage

As you work with Docker, your system can accumulate a large number of images, containers, volumes, and other data. This can lead to disk space issues over time. Managing storage effectively is critical to keeping your development environment healthy.

Here are a few common practices for managing Docker storage:

#Clean up unused images

To remove unused or untagged (dangling) images, you can run:

#Remove all stopped containers

If you want to remove containers that are no longer running, use:

Also check: How to Deploy a Docker Container on Kubernetes

#Check disk usage

Docker has a built-in command to check how much disk space is being used by images, containers, and volumes. Use this command:

This will give you a breakdown of the storage consumption and help you decide if it’s time to prune unused images or containers.

TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          1         1         13.26kB   0B (0%)
Containers      1         0         0B        0B
Local Volumes   0         0         0B        0B
Build Cache     0         0         0B        0B

Also read: How to Build a Docker Image

#Change docker’s storage location

If your system’s default storage location runs low on space, you can configure Docker to use a different directory. To do this, you’ll need to modify the docker.service file and change the --data-root parameter. Here’s a basic guide on how to do this on Linux:

1. Stop Docker:

sudo systemctl stop docker

2. Create or Modify the Docker service file located at /etc/docker/daemon.json and add the new storage location:

{
  "data-root": "/new/path/to/docker"
}

3. Restart Docker:

sudo systemctl start docker

By default, Docker uses the system’s main disk for storage, but by changing the data-root parameter, you can configure it to use an external disk or any other location that better suits your needs.

Also read: How to run Docker on bare metal cloud

#Conclusion

Understanding where Docker stores its images is an important part of mastering containerized applications. On Linux, this data is typically stored in /var/lib/docker, while on Windows and macOS, Docker uses a virtual machine to manage storage. Keeping track of your image storage and cleaning up unused images can help you optimize disk usage and maintain a smooth-running development environment.

By regularly managing Docker’s storage through pruning and moving the storage location when necessary, you can prevent your system from becoming overwhelmed with unused containers and images. Docker’s flexibility allows you to adjust these settings according to your project’s needs, ensuring your workflow remains efficient.

Where are Docker Images Stored? Docker Container Paths Explained

By Sebastian Sigl

Docker has been widely adopted and is used to run and scale applications in production. Additionally, it can be used to start applications quickly by executing a single Docker command.

Companies also are investing more and more effort into improving development in local and remote Docker containers, which comes with a lot of advantages as well.

You can get the basic information about your Docker configuration by executing:

$ docker info

...
 Storage Driver: overlay2
 Docker Root Dir: /var/lib/docker
...

The output contains information about your storage driver and your docker root directory.

The storage location of Docker images and containers

A Docker container consists of network settings, volumes, and images. The location of Docker files depends on your operating system. Here is an overview for the most used operating systems:

  • Ubuntu: /var/lib/docker/
  • Fedora: /var/lib/docker/
  • Debian: /var/lib/docker/
  • Windows: C:\ProgramData\DockerDesktop
  • MacOS: ~/Library/Containers/com.docker.docker/Data/vms/0/

In macOS and Windows, Docker runs Linux containers in a virtual environment. Therefore, there are some additional things to know.

Docker for Mac

Docker is not natively compatible with macOS, so Hyperkit is used to run a virtual image. Its virtual image data is located in:

~/Library/Containers/com.docker.docker/Data/vms/0

Within the virtual image, the path is the default Docker path /var/lib/docker.

You can investigate your Docker root directory by creating a shell in the virtual environment:

$ screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty

You can kill this session by pressing Ctrl+a, followed by pressing k and y.

Docker for Windows

On Windows, Docker is a bit fractioned. There are native Windows containers that work similarly to Linux containers. Linux containers are run in a minimal Hyper-V based virtual environment.

The configuration and the virtual image to execute linux images are saved in the default Docker root folder.

C:\ProgramData\DockerDesktop

If you inspect regular images then you will get linux paths like:

$ docker inspect nginx

...
"UpperDir": "/var/lib/docker/overlay2/585...9eb/diff"
...

You can connect to the virtual image by:

docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -i sh

There, you can go to the referenced location:

$ cd /var/lib/docker/overlay2/585...9eb/
$ ls -lah

drwx------    4 root     root        4.0K Feb  6 06:56 .
drwx------   13 root     root        4.0K Feb  6 09:17 ..
drwxr-xr-x    3 root     root        4.0K Feb  6 06:56 diff
-rw-r--r--    1 root     root          26 Feb  6 06:56 link
-rw-r--r--    1 root     root          57 Feb  6 06:56 lower
drwx------    2 root     root        4.0K Feb  6 06:56 work

The internal structure of the Docker root folder

Inside /var/lib/docker, different information is stored. For example, data for containers, volumes, builds, networks, and clusters.

$ ls -la /var/lib/docker

total 152
drwx--x--x   15 root     root          4096 Feb  1 13:09 .
drwxr-xr-x   13 root     root          4096 Aug  1  2019 ..
drwx------    2 root     root          4096 May 20  2019 builder
drwx------    4 root     root          4096 May 20  2019 buildkit
drwx------    3 root     root          4096 May 20  2019 containerd
drwx------    2 root     root         12288 Feb  3 19:35 containers
drwx------    3 root     root          4096 May 20  2019 image
drwxr-x---    3 root     root          4096 May 20  2019 network
drwx------    6 root     root         77824 Feb  3 19:37 overlay2
drwx------    4 root     root          4096 May 20  2019 plugins
drwx------    2 root     root          4096 Feb  1 13:09 runtimes
drwx------    2 root     root          4096 May 20  2019 swarm
drwx------    2 root     root          4096 Feb  3 19:37 tmp
drwx------    2 root     root          4096 May 20  2019 trust
drwx------   15 root     root         12288 Feb  3 19:35 volumes

Docker images

The heaviest contents are usually images. If you use the default storage driver overlay2, then your Docker images are stored in /var/lib/docker/overlay2. There, you can find different files that represent read-only layers of a Docker image and a layer on top of it that contains your changes.

Let’s explore the content by using an example:

$ docker image pull nginx
$ docker image inspect nginx

[
    {
        "Id": "sha256:207...6e1",
        "RepoTags": [
            "nginx:latest"
        ],
        "RepoDigests": [
            "nginx@sha256:ad5...c6f"
        ],
        "Parent": "",
 ...
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 126698063,
        "VirtualSize": 126698063,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/585...9eb/diff:
                             /var/lib/docker/overlay2/585...9eb/diff",
                "MergedDir": "/var/lib/docker/overlay2/585...9eb/merged",
                "UpperDir": "/var/lib/docker/overlay2/585...9eb/diff",
                "WorkDir": "/var/lib/docker/overlay2/585...9eb/work"
            },
...

The LowerDir contains the read-only layers of an image. The read-write layer that represents changes are part of the UpperDir. In my case, the NGINX UpperDir folder contains the log files:

$ ls -la /var/lib/docker/overlay2/585...9eb/diff

total 8
drwxr-xr-x    2 root     root    4096 Feb  2 08:06 .
drwxr-xr-x    3 root     root    4096 Feb  2 08:06 ..
lrwxrwxrwx    1 root     root      11 Feb  2 08:06 access.log -> /dev/stdout
lrwxrwxrwx    1 root     root      11 Feb  2 08:06 error.log -> /dev/stderr

The MergedDir represents the result of the UpperDir and LowerDir that is used by Docker to run the container. The WorkDir is an internal directory for overlay2 and should be empty.

Docker Volumes

It is possible to add a persistent store to containers to keep data longer than the container exists or to share the volume with the host or with other containers. A container can be started with a volume by using the -v option:

$ docker run --name nginx_container -v /var/log nginx

We can get information about the connected volume location by:

$ docker inspect nginx_container

...
"Mounts": [
            {
                "Type": "volume",
                "Name": "1e4...d9c",
                "Source": "/var/lib/docker/volumes/1e4...d9c/_data",
                "Destination": "/var/log",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
...

The referenced directory contains files from the location /var/log of the NGINX container.

$ ls -lah /var/lib/docker/volumes/1e4...d9c/_data

total 88
drwxr-xr-x    4 root     root        4.0K Feb  3 21:02 .
drwxr-xr-x    3 root     root        4.0K Feb  3 21:02 ..
drwxr-xr-x    2 root     root        4.0K Feb  3 21:02 apt
-rw-rw----    1 root     43             0 Jan 30 00:00 btmp
-rw-r--r--    1 root     root       34.7K Feb  2 08:06 dpkg.log
-rw-r--r--    1 root     root        3.2K Feb  2 08:06 faillog
-rw-rw-r--    1 root     43         29.1K Feb  2 08:06 lastlog
drwxr-xr-x    2 root     root        4.0K Feb  3 21:02 nginx
-rw-rw-r--    1 root     43             0 Jan 30 00:00 w

Clean up space used by Docker

It is recommended to use the Docker command to clean up unused containers. Container, networks, images, and the build cache can be cleaned up by executing:

$ docker system prune -a

Additionally, you can also remove unused volumes by executing:

$ docker volumes prune

Summary

Docker is an important part of many people’s environments and tooling. Sometimes, Docker feels a bit like magic by solving issues in a very smart way without telling the user how things are done behind the scenes. Still, Docker is a regular tool that stores its heavy parts in locations that can be opened and changed.

Sometimes, storage can fill up quickly. Therefore, it’s useful to inspect its root folder, but it is not recommended to delete or change any files manually. Instead, the prune commands can be used to free up disk space.

I hope you enjoyed the article. If you like it and feel the need for a round of applause, follow me on Twitter. I work at eBay Kleinanzeigen, one of the biggest classified companies globally. By the way, we are hiring!

Happy Docker exploring :)

References

  • Docker storagediver documentation
    https://docs.docker.com/storage/storagedriver/
  • Documentation Overlay filesystem
    https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt

Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started

Where are Docker Images stored on your Docker host machine? This is a fairly common question and one I will aim to tackle here! The answer is that it depends on what system you are running docker on and which Docker storage driver you are using. You may be running Docker on Linux (which is what I’m using for this article) or Windows or other. This article will show you how to find where the docker images are stored on your docker host system by showing you what commands you can run to get the information you need.

To get started, check out what images you currently have. You can view what Docker images you have on your system by running the docker images command:

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
python              latest              9038c75f5336        12 hours ago        933MB
nginx               latest              5ad3bd0e67a9        2 days ago          127MB
nginx                             5a3221f0137b        5 months ago        126MB
ubuntu              latest              a2a15febcdf3        5 months ago        64.2MB

Using Docker Info to Find the Docker Image Storage Location

To find where your images are stored, you can first run the Docker info command, which will list the location of your Docker root directory:

# docker info

This will output quite a lot of information, but you can make it a little easier to find what we are looking for by searching specifically for the root directory line using grep:

$ docker info | grep "Docker Root Dir"
Docker Root Dir: /var/lib/docker

Where are Docker Images Stored on Linux

As you can see from the output above, on my Centos 7 system, the Docker root directory is in /var/lib/docker. Looking inside, there will be a bunch of directories:

drwx------.  2 root root   23 Jan 16  2019 builder
drwx------.  4 root root   87 Jan 16  2019 buildkit
drwx------.  3 root root   19 Jan 16  2019 containerd
drwx------.  3 root root   77 Aug 27 11:33 containers
drwx------.  5 root root   50 Aug 20 14:03 devicemapper
drwx------.  4 root root   35 Aug 20 13:36 image
drwxr-x---.  3 root root   18 Jan 16  2019 network
drwx------.  4 root root   30 Jan 16  2019 plugins
drwx------.  2 root root    6 Jan 24 11:12 runtimes
drwx------.  2 root root    6 Jan 16  2019 swarm
drwx------.  2 root root    6 Jan 24 11:12 tmp
drwx------.  2 root root    6 Jan 16  2019 trust
drwx------.  2 root root   30 Aug 20 13:36 vfs
drwx------.  2 root root   24 Jan 16  2019 volumes

Looking inside the images directory on my system, there are two subdirectories:

drwx------.  5 root root   77 Aug 27 11:21 devicemapper
drwx------.  5 root root   77 Aug 20 13:36 vfs

These relate to the storage driver that Docker is using for storage. On my Centos system this is devicemapper, on the version of Docker that I am using. However, on a different host OS you may find this to be overlay, overlay2, btrfs, devicemapper or zfs. Note that you can manually set the driver – I’ve written an article covering this here. As mentioned in that article, you can easily check what driver you are currently using by running:

$ docker info | grep "Storage Driver"

Looking inside my /var/lib/docker/image/devicemapper directory I can see:

drwx------. 4 root root   56 Aug 20 14:03 distribution
drwx------. 4 root root   35 Jan 16  2019 imagedb
drwx------. 5 root root   42 Aug 20 14:03 layerdb
-rw-------. 1 root root 1.5K Jan 24 11:39 repositories.json

Running a ‘du –summarize -h’ here shows that this isn’t the location of the image file data as the total storage used amounts to only 3.1M.

du --summarize -h
3.1M .

Instead, this location contains information about the docker images. The image data itself can be found under the folder corresponding to the storage driver being used. So, in my case, I need to look into /var/lib/docker/devicemapper. Navigating to this directory, then running ‘du’, gives the following output:

$ du -h --summarize
1.5G .

Of the subdirectories here, the data one stores the images and the metadata directory stores the image metadata.

/var/lib/docker/devicemapper/devicemapper/data - stores the images
/var/lib/docker/devicemapper/devicemapper/metadata - contains the metadata

I ran through all the above on a Centos system. To summarise, the docker image locations on other popular Linux distributions are:

  • Ubuntu: /var/lib/docker/
  • Fedora: /var/lib/docker/
  • Debian: /var/lib/docker/

Where are Docker Images Stored on Windows ?

On windows, the default location for docker images is C:\ProgramData\DockerDesktop

What about Mac ?

On a Mac, the default location for Docker images is ~/Library/Containers/com.docker.docker/Data/vms/0/. Note than on Windows and Mac, Docker runs Linux containers in a virtual environment.

Hopefully this has helped you better understand how and where Docker stores its data, and helps answer the question of where Docker images are stored on your Docker host system.

Learning Docker?

If you are starting out, then I highly recommend this book.

Are you thirsty for more?

Then it’s time to take your Docker skills to the next level with this book (It’s my favorite) and, check out my page on Docker Certification.

Docker images are a crucial component of containerized software, and understanding where they are stored on your system is essential for optimizing your Docker environment.

Finding the storage location of Docker images varies depending on the operating system you are using. For Ubuntu, Fedora, and Debian, the default location is

. On Windows, the images are stored in

1

C:ProgramDataDockerDesktop

, while on MacOS, you can find them in

1

~/Library/Containers/com.docker.docker/Data/vms/0/

.

The images are stored in the overlay2 directory, and each image is composed of read-only layers and a layer for changes. The metadata about the images is stored in the

directory.

Docker volumes play a crucial role in persisting data across containers. You can add volumes to containers using the

option. To find the location of the connected volume, you can inspect the container.

It is important to note that manually deleting or modifying files in the Docker directories can lead to issues. Docker provides specific commands like

and

to safely clean up unused containers, networks, images, and volumes.

Key Takeaways:

  • Docker images are stored in different locations depending on the operating system.
  • For Ubuntu, Fedora, and Debian, the default storage location is

    .

  • On Windows, Docker images are stored in

    1

    C:ProgramDataDockerDesktop

    .

  • MacOS stores Docker images in

    1

    ~/Library/Containers/com.docker.docker/Data/vms/0/

    .

  • Docker volumes allow data to be persisted across containers and can be added using the

    option.

Docker Image Storage Locations for Different Operating Systems

The storage location of Docker images varies depending on the operating system you are using. To give you a better understanding, let’s explore the specific storage locations for Docker images on various operating systems, including Ubuntu, Fedora, Debian, Windows, and MacOS.

On Ubuntu, Fedora, and Debian, Docker images are stored in the /var/lib/docker/ directory. This is where you’ll find the container image storage for these operating systems. The images are stored in the overlay2 directory within this path. Additionally, the metadata about the images can be found in the /var/lib/docker/graph directory.

In the case of Windows, the default storage location for Docker images is C:ProgramDataDockerDesktop. This is where you’ll find the container image storage on Windows systems. On MacOS, the images are stored in ~/Library/Containers/com.docker.docker/Data/vms/0/.

It’s important to note that each Docker image consists of read-only layers and a layer for changes. These layers are stored within the aforementioned storage locations. Docker volumes, on the other hand, allow for persistent data across containers. You can add volumes to containers using the -v option, and by inspecting the container, you can find the location of the connected volume.

Operating System Storage Location
Ubuntu, Fedora, Debian /var/lib/docker/
Windows C:ProgramDataDockerDesktop
MacOS ~/Library/Containers/com.docker.docker/Data/vms/0/

It’s important to avoid manually deleting or changing any files within the Docker directories, as this can cause issues. Docker provides useful commands like docker system prune and docker volumes prune to clean up unused containers, networks, images, and volumes. Utilizing these commands will help keep your Docker image storage organized and optimized.

Default Storage Locations for Ubuntu, Fedora, and Debian

For Ubuntu, Fedora, and Debian users, Docker images are stored in the

directory by default. This directory contains the overlay2 directory, where the images are stored. Each Docker image is composed of multiple layers, with the read-only layers stored in the overlay2 directory and a separate layer for changes made to the image.

The metadata about the Docker images, such as their tags and labels, is stored in the

directory. This directory contains important information about the images, allowing Docker to manage and manipulate them efficiently.

When working with Docker volumes, which enable data persistence across containers, you can add them to your containers using the

option. By inspecting the container, you can find the location of the connected volume, providing a convenient way to manage and access the persistent data.

It is important to note that manually deleting or modifying any files within the Docker directories can lead to issues or data corruption. Instead, Docker provides useful commands like

and

to clean up unused containers, networks, images, and volumes, ensuring the efficient management of Docker image storage.

Operating System Default Docker Image Storage Location
Ubuntu /var/lib/docker/
Fedora /var/lib/docker/
Debian /var/lib/docker/

Docker Image Storage on Windows

Windows users can find Docker images stored in the C:ProgramDataDockerDesktop directory by default. This directory serves as the default location for storing all Docker images on Windows operating systems. It is important to note that this location may vary depending on the version of Docker and Windows being used.

The images are stored in the overlay2 directory within the DockerDesktop folder. This directory contains all the layers and changes associated with the Docker images. Each image is composed of read-only layers, which include the base image and any subsequent layers added during the container’s creation or modification process.

In addition to the overlay2 directory, Docker also stores metadata about the images in the /var/lib/docker/graph directory. This metadata contains information about the image, such as its ID, tags, and size. It is important to keep these directories intact and avoid manually deleting or modifying any files within them, as this can lead to potential issues with Docker functionality.

To manage Docker image storage on Windows, it is recommended to use Docker commands such as

and

. These commands help clean up unused containers, networks, images, and volumes, ensuring efficient storage usage and preventing any unnecessary clutter.

Docker Image Storage on Windows
Default Location C:ProgramDataDockerDesktop
Image Storage Directory overlay2
Metadata Storage Directory /var/lib/docker/graph
Recommended Commands docker system prune, docker volumes prune

Docker Image Storage on MacOS

MacOS users can find Docker images stored in the

1

~/Library/Containers/com.docker.docker/Data/vms/0/

directory by default. The images are stored in the

directory, which consists of read-only layers and a layer for changes. To gain more insights into the images, the metadata is stored in the

directory.

Docker volumes play a crucial role in persisting data across containers. By using the

option, users can add volumes to containers. The location of the connected volume can be found by inspecting the container. This feature is particularly useful for managing Docker image storage and ensuring the availability of data when containers are restarted or recreated.

It is essential to exercise caution when handling Docker image storage on MacOS. Manual deletion or modification of files within the Docker directories can lead to unexpected issues. To avoid potential problems, Docker provides useful commands such as

and

. These commands help clean up unused containers, networks, images, and volumes, ensuring efficient and reliable Docker image storage management.

Operating System Default Storage Location
MacOS

1

~/Library/Containers/com.docker.docker/Data/vms/0/

Ubuntu, Fedora, Debian

1

/var/lib/docker/

Windows

1

C:ProgramDataDockerDesktop

The Structure of Docker Images

Docker images follow a specific structure, consisting of read-only layers and a layer for changes within each image. This structure allows for efficient and lightweight image creation, deployment, and management.

Each Docker image is built from a base image, which serves as the foundation. On top of the base image, multiple read-only layers are added, each representing a specific component or modification to the image. These layers are stacked on top of each other, creating a layered file system.

The topmost layer is the layer for changes, also known as the container layer. This layer contains any modifications or additions made to the base image and read-only layers. It allows for customization and flexibility in running containers based on the image.

It is important to note that Docker images are designed to be lightweight and shareable. This is achieved by sharing common layers across multiple images, reducing disk usage and speeding up image creation and deployment.

Docker Image Structure Table

Layer Description
Base Image The foundation image for the Docker image.
Read-only Layers Additional layers containing specific components or modifications.
Layer for Changes The topmost layer that allows customization and flexibility.

Understanding the structure of Docker images is crucial for efficiently managing and utilizing them in your environment. By leveraging the layered file system and the layer for changes, you can create and deploy lightweight and scalable containers, saving valuable resources and time.

Docker Volumes for Persistent Data

Docker volumes offer a way to persist data across containers, ensuring that important information is not lost when containers are restarted or replaced. By adding volumes to containers using the -v option, you can designate specific directories or files within the container to be mapped to persistent storage on the host system.

When a Docker volume is created, it is stored in a specific location on the host system. To find the location of a connected volume, you can inspect the container using the docker inspect command. This will provide detailed information about the container, including the mount point of the connected volume.

Managing Docker image storage also involves being cautious about manually deleting or changing files in the Docker directories. This can lead to unexpected issues and data loss. Instead, Docker provides a set of commands to safely clean up unused resources. For example, the docker system prune command can be used to remove unused containers, networks, images, and volumes, freeing up disk space and ensuring a more efficient storage environment.

Command Description
docker system prune Remove unused containers, networks, images, and volumes
docker volume prune Remove unused volumes

By following best practices for managing Docker image storage and utilizing Docker volumes effectively, you can ensure the reliability and availability of your data across containers. This allows you to focus on your application development and deployment, without worrying about data loss or inconsistencies.

Best Practices for Docker Image Storage

To maximize the benefits of Docker image storage, it is crucial to follow best practices that promote efficiency and minimize potential issues. By implementing the following recommendations, you can ensure that your Docker images are well-organized and effectively managed.

1. Regularly clean up unused Docker resources

Over time, unused containers, networks, images, and volumes can accumulate, consuming valuable disk space. To prevent this, periodically perform system cleanups using Docker’s built-in commands. For example, the

command removes all unused resources, while

specifically targets unused volumes. These commands help optimize storage usage and maintain a tidy Docker environment.

2. Leverage Docker volumes for persistent data

Docker volumes provide a reliable way to persist data across containers. When adding volumes to your containers using the

option, make sure to choose appropriate locations for storing the data. By separating the storage of your volumes from the container itself, you can easily manage, backup, and restore the data even if the container is removed or replaced.

3. Avoid manually modifying Docker directories

It is essential to refrain from manually deleting or modifying any files within the Docker directories. Doing so can lead to unexpected issues and data corruption. Instead, rely on Docker’s provided commands and APIs to manage your Docker environment. This ensures the integrity and stability of your Docker images and prevents potential conflicts.

By adhering to these best practices for Docker image storage, you can maintain a well-structured Docker environment, minimize storage usage, and mitigate the risk of data loss. Remember to regularly clean up unused resources, utilize Docker volumes for persistent data, and rely on Docker’s recommended methods for managing your images. By doing so, you can optimize the efficiency and reliability of your Docker workflows.

Conclusion

Understanding where Docker images are stored on your system is vital for effectively managing and optimizing your Docker environment. By knowing the default storage locations and following best practices, you can ensure the smooth functioning of your containerized software.

For Ubuntu, Fedora, and Debian operating systems, Docker images are stored in the

directory. On Windows, the default location is

1

C:ProgramDataDockerDesktop

, while on MacOS, the images are stored in

1

~/Library/Containers/com.docker.docker/Data/vms/0/

.

Docker images are stored in the overlay2 directory, consisting of read-only layers and a layer for changes. The metadata about the images can be found in the

directory.

To persist data across containers, Docker volumes can be added using the

option. You can inspect the container to find the location of the connected volume. It is important to avoid manually deleting or changing files in the Docker directories, as this can cause issues. Docker provides commands like

and

to clean up unused containers, networks, images, and volumes.

By understanding where Docker images are stored and following best practices for managing storage, you can ensure the proper functioning of your Docker environment. Stay informed about the default storage locations for your operating system and leverage Docker volumes for effective data persistence. With these practices in place, you can optimize your containerized software and maintain a reliable and efficient Docker setup.

FAQ

Where are Docker images stored on my system?

The location of Docker images depends on the operating system. For Ubuntu, Fedora, and Debian, the images are stored in

. On Windows, the default location is

1

C:ProgramDataDockerDesktop

, while on MacOS, the images are stored in

1

~/Library/Containers/com.docker.docker/Data/vms/0/

.

How can I find the location of a connected Docker volume?

To find the location of a connected Docker volume, you can inspect the container. This will provide you with information about the volume’s location on your system.

What is the directory structure of Docker images?

Docker images are stored in the overlay2 directory. Each image consists of read-only layers and a layer for changes. The metadata about the images is stored in the

directory.

How can I manage Docker image storage?

Docker provides commands such as

and

to clean up unused containers, networks, images, and volumes. It is important not to manually delete or change any files in the Docker directories, as this can cause issues.

What are Docker volumes and how do they work?

Docker volumes allow data to be persisted across containers. You can add volumes to containers using the

option. This allows you to separate container data from the image and manage data persistence more effectively.

What are some best practices for Docker image storage?

Some best practices for Docker image storage include optimizing storage usage, regularly cleaning up unused containers and images, using a proper Docker image repository, and following recommended security measures to protect your images.

  • About the Author
  • Latest Posts

Mark is a senior content editor at Text-Center.com and has more than 20 years of experience with linux and windows operating systems. He also writes for Biteno.com

Docker Desktop в Windows 10 создаёт WSL 2 дистрибутив docker-desktop-data и соответствующий виртуальный диск для него, который обычно расположен здесь:

%USERPROFILE%\AppData\Local\Docker\wsl\data\ext4.vhdx

Именно тут хранятся все контейнеры и образы докера. Для перемещения этого диска в другое место нужно выполнить несколько шагов.

Шаг 1. Выйти из Docker Desktop (если запущен).

Завершение работы Docker Desktop

Шаг 2. В командной строке выполняем команду для вывода списка дистрибутивов Linux:

wsl --list -v
  • wsl — команда для взаимодействия с подсистемой Linux в Windows;
  • --list — вывести список дистрибутивов Linux;
  • -v — вывести расширенную информацию.

Результат выполнения команды должен быть примерно таким:

Результат выполнения команды wsl для вывода списка дистрибутивов Linux

Список дистрибутивов Linux с расширенной информацией

Состояние дистрибутивов (STATE) должно быть Stopped.

Шаг 3. Экспортируем данные в файл. Можно экспортировать в любое место, этот файл позже можно будет удалить. Например, в корень диска f::

wsl --export docker-desktop-data "f:\docker-desktop-data.tar"

Шаг 4. Удалим дистрибутив docker-desktop-data из WSL. Во время выполнения этой операции виртуальный диск со всеми данными докера будет удалён.

wsl --unregister docker-desktop-data

Шаг 5. Импортируем дистрибутив обратно в WSL, но теперь в новое место. Например, в папку f:\docker\wsl (папка должна быть предварительно создана):

wsl --import docker-desktop-data "f:\docker\wsl" "f:\docker-desktop-data.tar" --version 2

Шаг 6. Запускаем Docker Desktop и проверяем, что всё работает. Если всё хорошо, можно удалить файл, который мы создали при экспорте дистрибутива на 3 шаге (f:\docker-desktop-data.tar).

На этом всё. Данные докера хранятся теперь в новом месте.

Статья основана на ответе на вопрос «How can I change the location of docker images when using Docker Desktop on WSL2 with Windows 10 Home?» cо StackOverflow.

При написании статьи использовалось следующее ПО:

  • Windows 10 Pro 20H2
  • Docker Desktop 3.5.1 (66090)

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Как называется аналог проводника windows в bios
  • Как определить ком порт usb устройства windows 10
  • Как установить mpich на windows
  • Как поменять раздел диска с gpt на mbr при установке windows 10
  • Free ftp server for windows server