Finding the location of docker images is a chore on a mac. Usually on most systems, you can see where the images and containers are located by running the command docker info
but no, that does not work on a mac. You see that command will tell you that the root directory is located at /var/lib/docker
, which on a mac is a non-existent directory.
There are two primary ways to get to this directory. Try option 1 first, if it does not work try option 2
Here is a little background information on the docker directory
On a mac our docker files are located inside of a virtual machine which is located in our user library directory: ~/Library/Containers/com.docker.docker/
This directory is easy to get to from the terminal, but if you try to get there via the finder you might notice that com.docker.docker does not appear visually under that directory name. When you navigate to ~/Library/Containers
you will see the folder name Docker instead. Take note, that is the com.docker.docker directory
Now to get to the root directory /var/lib/docker
we must access the docker virtual machine being used on our mac.
Option 1
Use the terminal application screen.
screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty
You should see a screen, where you can enter the command
cd /var/lib/docker
Option 2
Now if you are unlucky and you get a permission denied error, you will need to try to access the docker virtual machine through a docker image:
To get around this error, we will install a debian docker image, run it, then enter the container with the nsenter tool
docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh
This will open the debian image and allow us to browse around the docker files via the sh shell
Now that the shell is available. let's type the command
cd /var/lib/docker
If the default storage driver overlay2 was used, then your Docker images are stored in the directory /var/lib/docker/overlay2
To get a detailed explanation of the docker run flags, type docker run --help
command in the terminal.
Sources
Learn more about nsenter linux tool on the redhat linux website.
Getting path and accessing persistent volumes in Docker for Mac by Tim Kamanin
Top comments (4)
On Mac os ventura version 13.0.1 and docker app version 4.14.0 (91374), the screen command just exits after a few seconds because the file ~/Library/Containers/com.docker.docker/Data/vms/0/tty doesn't exist.
I couldn't find the tty on my Mac OS 12.6.3 either. Waiting for more updates.
The location might have changed again since posting this.
Monterey 12.4 - no container dir found under any of the paths mentioned. I still haven't found where they are stored.
Still in the same spot.
It's confusing because the path is:
~/Library/Containers/com.docker.docker/Data/
But Finder shows it as:
Macintosh HD ∙ Users ∙ $user ∙ Library ∙ Containers ∙ Docker ∙ Data