Where are images stored on Mac OS X?

I just installed Docker for Mac and Kinematic. It works fine and I can pull an image (with the command line or the Kinematic UI) and run a container (again with the command and the UI).

But I can’t seem to find the physical location of the images on the host Mac OS X, where should they be? Cleaning up with docker rm and docker rmi also works, but I would like to browse the folder :wink:

1 Like

It depends on the driver being used, but the default is: $HOME/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2

2 Likes

I’m on mac OS X 10.12.3 using kitematic 0.13.1.

My VM images are stored here: /Users/USERNAME/.docker/machine/machines
See: http://stackoverflow.com/questions/32605383/location-of-docker-images-downloaded-by-docker-1-9-1-on-mac-os-x

You should see a “default” folder here that is your base VM. If you’ve created others, they’d be here as well.

This is different than the docker containers you create or download.

Those are stored at …

1 Like

Hi

I am running docker on Mac High Sierra ( version 10.13.3) . docker inspect on my container shows path is /var/lib/docker .But there is no such folder created. Could some one help with image location on Mac pls. And also why docker inspect shows different path? Am i missing something here ? Logs below

docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0545bfe74ae2 centos “/bin/bash” 7 minutes ago Up 7 minutes stoic_curran
Vipins-MacBook-Air:Library root# docker inspect 0545bfe74ae2
[
{
“Id”: “0545bfe74ae25e9e2c034b816f4926d1aac5ba6d496e20f8131fcb43f96c5d44”,
“Created”: “2018-06-13T03:43:34.009542284Z”,
“Path”: “/bin/bash”,
“Args”: [],
“State”: {
“Status”: “running”,
“Running”: true,
“Paused”: false,
“Restarting”: false,
“OOMKilled”: false,
“Dead”: false,
“Pid”: 1701,
“ExitCode”: 0,
“Error”: “”,
“StartedAt”: “2018-06-13T03:43:34.621987883Z”,
“FinishedAt”: “0001-01-01T00:00:00Z”
},
“Image”: “sha256:49f7960eb7e4cb46f1a02c1f8174c6fac07ebf1eb6d8deffbcb5c695f1c9edd5”,
“ResolvConfPath”: “/var/lib/docker/containers/0545bfe74ae25e9e2c034b816f4926d1aac5ba6d496e20f8131fcb43f96c5d44/resolv.conf”,
“HostnamePath”: “/var/lib/docker/containers/0545bfe74ae25e9e2c034b816f4926d1aac5ba6d496e20f8131fcb43f96c5d44/hostname”,
“HostsPath”: “/var/lib/docker/containers/0545bfe74ae25e9e2c034b816f4926d1aac5ba6d496e20f8131fcb43f96c5d44/hosts”,
“LogPath”: “/var/lib/docker/containers/0545bfe74ae25e9e2c034b816f4926d1aac5ba6d496e20f8131fcb43f96c5d44/0545bfe74ae25e9e2c034b816f4926d1aac5ba6d496e20f8131fcb43f96c5d44-json.log”,
“Name”: “/stoic_curran”,
“RestartCount”: 0,
“Driver”: “overlay2”,
“Platform”: “linux”,
“MountLabel”: “”,
“ProcessLabel”: “”,
“AppArmorProfile”: “”,
“ExecIDs”: null,
“HostConfig”: {
“Binds”: null,
“ContainerIDFile”: “”,
“LogConfig”: {
“Type”: “json-file”,
“Config”: {}
},
“NetworkMode”: “default”,
“PortBindings”: {},
“RestartPolicy”: {
“Name”: “no”,
“MaximumRetryCount”: 0
},
“AutoRemove”: false,
“VolumeDriver”: “”,
“VolumesFrom”: null,
“CapAdd”: null,
“CapDrop”: null,
“Dns”: [],
“DnsOptions”: [],
“DnsSearch”: [],
“ExtraHosts”: null,
“GroupAdd”: null,
“IpcMode”: “shareable”,
“Cgroup”: “”,
“Links”: null,
“OomScoreAdj”: 0,
“PidMode”: “”,
“Privileged”: false,
“PublishAllPorts”: false,
“ReadonlyRootfs”: false,
“SecurityOpt”: null,
“UTSMode”: “”,
“UsernsMode”: “”,
“ShmSize”: 67108864,
“Runtime”: “runc”,
“ConsoleSize”: [
0,
0
],
“Isolation”: “”,
“CpuShares”: 0,
“Memory”: 0,
“NanoCpus”: 0,
“CgroupParent”: “”,
“BlkioWeight”: 0,
“BlkioWeightDevice”: [],
“BlkioDeviceReadBps”: null,
“BlkioDeviceWriteBps”: null,
“BlkioDeviceReadIOps”: null,
“BlkioDeviceWriteIOps”: null,
“CpuPeriod”: 0,
“CpuQuota”: 0,
“CpuRealtimePeriod”: 0,
“CpuRealtimeRuntime”: 0,
“CpusetCpus”: “”,
“CpusetMems”: “”,
“Devices”: [],
“DeviceCgroupRules”: null,
“DiskQuota”: 0,
“KernelMemory”: 0,
“MemoryReservation”: 0,
“MemorySwap”: 0,
“MemorySwappiness”: null,
“OomKillDisable”: false,
“PidsLimit”: 0,
“Ulimits”: null,
“CpuCount”: 0,
“CpuPercent”: 0,
“IOMaximumIOps”: 0,
“IOMaximumBandwidth”: 0
},
“GraphDriver”: {
“Data”: {
“LowerDir”: “/var/lib/docker/overlay2/1a95cc49d89829285e77ed99a67f42c64466c421a01c11b2b085aedb59220371-init/diff:/var/lib/docker/overlay2/15b85ac67b96997c979612b11803fad7be9ae06b8ffc6e77e1c03d58fe5dcea5/diff”,
“MergedDir”: “/var/lib/docker/overlay2/1a95cc49d89829285e77ed99a67f42c64466c421a01c11b2b085aedb59220371/merged”,
“UpperDir”: “/var/lib/docker/overlay2/1a95cc49d89829285e77ed99a67f42c64466c421a01c11b2b085aedb59220371/diff”,
“WorkDir”: “/var/lib/docker/overlay2/1a95cc49d89829285e77ed99a67f42c64466c421a01c11b2b085aedb59220371/work”
},
“Name”: “overlay2”
},
“Mounts”: [],
“Config”: {
“Hostname”: “0545bfe74ae2”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: true,
“AttachStdout”: true,
“AttachStderr”: true,
“Tty”: true,
“OpenStdin”: true,
“StdinOnce”: true,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”
],
“Cmd”: [
“/bin/bash”
],
“Image”: “centos”,
“Volumes”: null,
“WorkingDir”: “”,
“Entrypoint”: null,
“OnBuild”: null,
“Labels”: {
“org.label-schema.schema-version”: “= 1.0 org.label-schema.name=CentOS Base Image org.label-schema.vendor=CentOS org.label-schema.license=GPLv2 org.label-schema.build-date=20180531”
}
},
“NetworkSettings”: {
“Bridge”: “”,
“SandboxID”: “d821d222acd141bc07c13333386f5da81b2beb339cf685ed6668ee3fdb210f40”,
“HairpinMode”: false,
“LinkLocalIPv6Address”: “”,
“LinkLocalIPv6PrefixLen”: 0,
“Ports”: {},
“SandboxKey”: “/var/run/docker/netns/d821d222acd1”,
“SecondaryIPAddresses”: null,
“SecondaryIPv6Addresses”: null,
“EndpointID”: “cc1fcf8cd30e856d1a89a77550207f114e342db219904c13ed4eca4cda6a0d5b”,
“Gateway”: “172.17.0.1”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “172.17.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“MacAddress”: “02:42:ac:11:00:02”,
“Networks”: {
“bridge”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: null,
“NetworkID”: “9d02913f2d7eaf950523473524322bf896e6e522c29360f50c1287b38b4e4bbb”,
“EndpointID”: “cc1fcf8cd30e856d1a89a77550207f114e342db219904c13ed4eca4cda6a0d5b”,
“Gateway”: “172.17.0.1”,
“IPAddress”: “172.17.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “02:42:ac:11:00:02”,
“DriverOpts”: null
}
}
}
}
]

ls -ld /var/lib/docker/containers/

ls: /var/lib/docker/containers/: No such file or directory

You are missing the subtlety from the previous replies that Docker does not run natively a Mac because the macOS kernel isn’t compatible (i.e., BSD vs Linux). Docker is actually running in a virtual machine using HyperKit. The Docker vm disc image defaults to being in either:

$HOME/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2

or

$HOME/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.raw

Depending on if you chose the raw filesystem or not. So the folder location of /var/lib/docker is inside of this virtual machine and not on your macOS filesystem which is why you can’t find it with ls.

You can use:

docker volume ls

to list the volumes in this folder, and use:

docker volume prune

command to remove unused container volumes.

BTW, this disk image never gets smaller. So as you added images to Docker and then remove them, removing them doesn’t take up any less space although when you add the next image it will reuse that space but once allocated it never shrinks.

~jr

1 Like

44%20PM

The default physical location is $HOME/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2 as @badonk mentioned. But you can change and specify a new “Disk Image Location” using Docker Desktop on your Mac as follows: Docker Desktop -> Preferences -> Disk [Tab] -> Move Disk Image. However, if you attempt to move the disk image to a location that already has one, you get a prompt asking if you want to use the existing image or replace it. You can find more information here on Docker official pages.

@badonk and @rofrano:

As of this morning, 2020/01/28, I took some time to cruise the internet and can reveal that the location has changed yet again… with the current Docker Desktop and Docker Enterprise innards, and running under MacOS Catalina, the VM images are stored at:

~/Library/Containers/com.docker.docker/Data/vms/{int}/data/Docker.raw

The base size for the Docker.raw file is 64 mb… and that’s the only image I currently have on my machine. I am just in the process of learning how to create images with Docker, and knowing where my VM images are kept was an important step in learning how Docker works on my machine.

I am assuming that the {int} will increment as different VM configurations are created and deployed.

4 Likes

Mine seems to be here:

/Users/USERNAME/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw

But my question is, where is the data kept for volumes? How do I access the volumes in the Linux VM on macOS to see the volumes in docker and access the files? And where do I place docker-compose.yaml files?

On wsl2 there are directories in file Explorer I can see, and open the files, or access them in the terminal. I need the equivalent in macOS.

You can use the docker inspect command to see the exact location of the data within the VM. You can also use the docker volume ls command to list the volumes.

For example: These are the volumes on my Mac right now:

$ docker volume ls

DRIVER    VOLUME NAME
local     lab-openshift_devcontainer_minikube-config
local     lab-openshift_devcontainer_postgres
local     vscode

Let’s say I want to know where the data for the vscode volume is being kept. I can use docker inspect to find that out.

$ docker inspect vscode
[
    {
        "CreatedAt": "2023-12-20T12:43:42Z",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/vscode/_data",
        "Name": "vscode",
        "Options": null,
        "Scope": "local"
    }
]

This is telling me that if I were to ssh into that VM, I can find the volume for vscode in the folder: /var/lib/docker/volumes/vscode/_data.

The easiest way to get at your data from your Mac, is to mount it to a container. For example like this:

$ docker run --rm -it -v vscode:/vscode ubuntu bash

root@b164e4417e24:/# ls -l /vscode
total 4
drwxr-xr-x 4 root root 4096 Dec 20 12:43 vscode-server

That command starts an ubuntu container and mounts the vscode volume at /vscode inside the container. Then I used the ls command to list it’s contents.

As you can see, there is a folder called vscode-server created in that volume which is mounted at /vscode. You can copy the data from the running ubuntu container with the docker cp command, or mount a local volume and copy to the data anywhere you want.

For example this will copy the contents of the folder into the current folder on your Mac:

docker run -d --name vscode -v vscode:/vscode busybox
docker cp vscode:/vscode .

That will leave you with a folder called vscode on your Mac with all the files that were in /vscode from the VM.

You will not see the data in the macOS Finder because it cannot be mounted to the macOS filesystem because it is inside the VM, but you can see the files from inside any container that has the volume mounted.

I’m guessing you want to edit files from outside the VM or running container. If that’s your intent, then I would use a filesystem mount and not have Docker manage the volume for you. That’s the whole purpose of filesystem mounts, i.e., you control where the data resides. Hope that helps.

~jr

1 Like

Wow, thank you very much for the detailed reply, I appreciate it.

I will look at this closely tomorrow as it’s almost 1am here.

And yes, I need to edit some files, so I will learn all about file system mounts, thanks again for pointing me in the right direction.

You’re welcome. Sorry for not giving you an example of using a filesystem mount. I should have done that.

To use your own folder you can do something like this:

docker run --rm -it -v /Users/USERNAME/mydata:/mydata -w /mydata ubuntu bash

That will share the folder /Users/USERNAME/mydata inside the container as the folder /mydata. Anything written to /mydata inside the container, is actually be written to /Users/USERNAME/mydata on your Mac. The -w /mydata parameter just makes /mydata the working folder when you and placed inside the container.

In a docker-compose.yaml file you would use a volume statement like this:

services:
  myapp:
    volumes:
      - /Users/USERNAME/mydata:/mydata
...

You can also use environment variables like $HOME which point to your home folder by using ${HOME} in the docker-compose file like this:

services:
  myapp:
    volumes:
      - ${HOME}/mydata:/mydata
...

This way if someone else runs it on their Mac it will use their home folder instead of hard-coding it to yours.

~jr

1 Like

Thank you once again!

I just mounted a directory named /mydata (Users/skeptical.me/mydata) in the Ubuntu container and confirmed it with ls - l /mydata

I’m just wondering, is that mount persistent, and if not how would I make it permanent?

It is persistent for the life of the container. If you remove the container (i.e., docker rm) you would have to start a new one with the same mount. But you can docker stop and docker start the container and the mount will still persist.

One thing you could do is use an alias. I have an alias that runs any docker image and mounts the current folder under a mount point called /app.

This is the alias:

alias dr='docker run --rm -it -h dev -v $(pwd):/app -w /app'

With this you can say:

dr ubuntu bash

and it will run a bash shell in a container from the ubuntu image and mount the current working directory under /app inside the container so that you can manipulate the files from inside or outside the container. So you could do something similar by creating an alias that adds your mount point to the docker command.

~jr

1 Like

Thank you very much, John. I had some containers that would reset on restart and I would lose all my data. I thought I had set the correct volume using Docker Desktop but it wasn’t working. So now, with your help, I’ve solved that issue.

Yea, without a volume mount, the data is gone once the container is gone. I’m glad that solved it for you. Take care,

~jr

1 Like