Where Docker Images are Stored
One question that often arises for both newcomers and seasoned Docker users alike is: "Where are Docker images stored?" Understanding the storage location of Docker images is crucial for managing disk space and optimizing Docker performance.
Whether you're running Docker on macOS, Windows, or Linux, this blog post will guide you on how to locate Docker images on each platform. Let’s get started!
Where Docker Images are Stored on macOS
The most important point to keep in mind is that Docker doesn't run natively on macOS. Instead, it operates within a virtual machine using HyperKit.
For Docker Desktop on macOS, Docker stores Docker images within a disk image file. But what exactly is a disk image file? In simple terms, a disk image file is a single, large file that acts like a virtual "hard drive" for the Docker virtual machine. It contains the entire file system used by Docker, including images, containers, and volumes.
To locate this disk image file, follow the steps below:
#1 Open Docker Desktop
Start Docker Desktop on your Mac if it's not already running.
#2 Open settings window
Once Docker Desktop is open, click on the Settings
icon (highlighted below) to open the Settings
window.
#3 Navigate to the "Advanced" tab
In the Settings
window, click on the Resources
tab, and then click on the Advanced
section.
#4 Find disk image location
Scroll down a bit in the Advanced
section until you see Disk image location
. Here, Docker Desktop displays the path to the disk image file on your Mac's file system, as highlighted below:
Note that the disk image is managed by the Docker Desktop virtual machine and is not meant to be manually modified or directly accessed. Instead, you should interact with Docker images through Docker CLI commands.
Where Docker Images are Stored on Linux
Unlike macOS, Docker runs natively on Linux. This means that Docker directly interacts with the Linux kernel and filesystem without the need for a virtual machine.
On Linux, all Docker-related data, including images, containers, volumes, and networks, is stored within the /var/lib/docker
directory, known as the root directory. The exact directory inside the root directory where images are stored depends on the storage driver being used. For example, if the storage driver is overlay2
, the image-related data will be stored within the subdirectory of /var/lib/docker/overlay2
.
To find out what storage driver you’re using, you can run the docker info
command and look for a field named Storage Driver
as shown below:
Note: While it's useful to know where Docker stores its image-related data, manually altering files or directories within /var/lib/docker
is not recommended, as it can disrupt Docker's operations and lead to data loss.
Where Docker Images are Stored on Windows
For Docker Desktop on Windows configured to use WSL 2 (recommended by Docker), Docker stores Docker images in a disk image. To locate it, follow the steps below:
#1 Open Docker Desktop
Start Docker Desktop on your machine if it's not already running.
#2 Open settings window
Once Docker Desktop is open, click on the Settings
icon (highlighted below) to open the Settings
window.
#3 Navigate to the "Advanced" tab
In the Settings
window, click on the Resources
tab, and then click on the Advanced
section.
#4 Find disk image location
Scroll down a bit in the Advanced
section until you see Disk image location
. Here, Docker Desktop displays the path to the disk image file on your Windows file system, as shown below:
Cleaning up Images Used by Docker
As you use Docker, over time, your system might accumulate many unused and "dangling" images. An unused image is an image not currently used by any container (stopped or running). A dangling image is an image that neither has a repository name nor a tag. It appears in Docker image listings as <none>:<none>
. These images can take up significant disk space, leading to inefficiencies and potential storage issues.
To address this, Docker provides a simple command: docker image prune
.
To remove all dangling images, run the following command:
docker image prune
This command will issue a prompt asking whether you want to remove all dangling images. Type y
and hit enter
to proceed.
To remove unused images, run the following command:
docker image prune -a
When you run this command, it’ll issue a warning and will prompt you to confirm whether you want to proceed or not. Type y
and hit enter
to proceed.
You should regularly clean up unused and dangling Docker images to maintain an efficient and clutter-free Docker environment.
Conclusion
Now you know where Docker images are stored on three different platforms: Linux, macOS, and Windows.
If you’re still unable to find the location where Docker images are stored, which may be due to a specific configuration not covered in this blog post, consider asking questions on platforms such as Stack Overflow and the Docker Community forum.
A deep understanding of Docker images, including knowledge of how to create and manage them, is crucial for mastering Docker. To help you with this, check out the blog posts below:
- How to Build a Docker Image With Dockerfile From Scratch
- How to Create Docker Image From a Container?
- How to Remove Unused and Dangling Docker Images?
- Why and How to Tag a Docker Image?
- What Are Docker Image Layers and How Do They Work?
- How to Run a Docker Image as a Container?
Interested in learning more about Docker? Check out the following courses from KodeKloud:
- Docker for the Absolute Beginner: This course will help you understand Docker using lectures and demos. You’ll get a hands-on learning experience and coding exercises that will validate your Docker skills. Additionally, assignments will challenge you to apply your skills in real-life scenarios.
- Docker Certified Associate Exam Course: This course covers all the required topics from the Docker Certified Associate Exam curriculum. The course offers several opportunities for practice and self-assessment. There are hundreds of research questions in multiple-choice format, practice tests at the end of each section, and multiple mock exams that closely resemble the actual exam pattern.