Where is /var/lib/docker on Mac/OS X

2020-01-25 12:27发布

问题:

I´m looking for the folder /var/lib/docker on my Mac after installing docker for Mac.

With docker info I get

    Containers: 5
     ...
    Server Version: 1.12.0-rc4
    Storage Driver: aufs
     Root Dir: /var/lib/docker/aufs
     Backing Filesystem: extfs
     Dirs: 339
     Dirperm1 Supported: true
    ...
    Name: moby
    ID: LUOU:5UHI:JFNI:OQFT:BLKR:YJIC:HHE5:W4LP:YHVP:TT3V:4CB2:6TUS
    Docker Root Dir: /var/lib/docker
    Debug Mode (client): false
    ....

But I don´t have a directory /var/lib/docker on my host.

I have checked /Users/myuser/Library/Containers/com.docker.docker/ but couldn´t find anything there. Any idea where it is located?

回答1:

See this answer

When using Docker for Mac Application, it appears that the containers are stored within the VM located at:

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



回答2:

As mentioned in the above answers, you will find it in:
screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

Once you get the tty running you can navigate to /var/lib/docker



回答3:

The other answers here are outdated if you're using Docker for Mac.

Here's how I was able to get into the VM. Run the command:

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

This is the default path, but you may need to first do: cd ~/Library/Containers/com.docker.docker/Data/vms

and then ls to see which directory your VM is in and replace the "0" accordingly.

When you're in, you might just see a blank screen. Hit your "Enter" key.

This page explains that to exit from the VM you need to "Ctrl-a" then "d"



回答4:

Just as @Dmitriy said:

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

and can use ctrl a + d to detach the screen

and use screen -dr to re-attach the screen again(since if you simply attach screen again, the terminal text will be garbled.)

Reference

or if you want to exit, use ctrl + a + k,then choose y to kill the screen.



回答5:

some what of a zombie thread but as I just found it here is another solution that doesn't need screen nor messes up shell etc.

The path listed from a docker volume inspect <vol_name>

returns the path for the container, something like:

"Mountpoint": "/var/lib/docker/volumes/coap_service_db_data/_data"

the _data component being the last component of the path you setup in the volumes: section of the service using a given volume eg:

volumes: - db_data:/var/lib/postgresql/data , obvs your mileage will vary.

To get there on the mac the easiest method I have found is to actually start a small container running and mount the root of the host to the /docker directory in the image, this gives you access to the volumes used on the host.

docker run --rm -it -v /:/docker alpine:edge

from this point you can cd to the volume

cd /var/lib/docker/volumes/coap_service_db_data/_data



回答6:

This path comes from Docker Host (not from MacOS) fefore "Docker for Mac Application" times, where where was a VirtualBox VM "default" and inside this VM mentioned path exists (for sure), now in "Docker for Mac Application" times there is a Docker.qcow2 image, which is qemu base vm. To jump inside this VM @mik-jagger way is ok (but there are few more)



回答7:

I would say that the file:

/var/run/docker.sock

Is actually at:

/Volumes/{DISKNAME}/var/run/docker.sock

If you run this, it should prove it, as long as your running VirtualBox 5.2.8 or later and the share for /Volumes is setup to be auto-mounted and permanent AND you generated the default docker-machine while on that version of Virtualbox:

#!/bin/bash
docker run -d --restart unless-stopped -p 9000:9000 \
-v /var/run/docker.sock:/var/run/docker.sock portainer/portainer \
--no-auth

Then, access Portainer at: 192.168.99.100:9000 or localhost:9000