Docker Community Forums

Share and learn in the Docker community.

/var/lib/docker does not exist on host


(Hyperknot) #1

Expected behavior

Both docker info and docker volumes tells me that my volumes are stored in /var/lib/docker/…
I guess that directory should be there, with volumes visible under it.

Actual behavior

Yet, /var/lib/docker doesn’t even exist on the host.

Information

8AD4FDA4-54A8-495C-AD0C-E74BC05CBD14
OS X 10.11.5

Steps to reproduce the behavior

  1. run docker info
  2. or run docker volume create --name test and docker volume inspect test
[
    {
        "Name": "test",
        "Driver": "local",
        "Mountpoint": "/var/lib/docker/volumes/test/_data",
        "Labels": {},
        "Scope": "local"
    }
]

(David Maze) #2

It’s hidden inside the xhyve virtual machine. But you don’t really need to look inside it. If you’re really curious you can use the magic screen command to get a shell in the VM, but mostly it’s all internal Docker details.

If you’re trying to access the volume data, I think the usual way is to launch another container: docker run -v test:/test -it ubuntu:16.04 bash will get a shell with the volume data visible in /test.


(Hyperknot) #3

OK, great, I see.

An other, related question. If I have VOLUME in Dockerfile or specify simply the target volume in command line as -v /data, and I run the container with --rm, then the volume gets destroyed after running.

But if I specify a name with -v data:/data then it survives --rm. Is that correct?

If it is, then what is the point of VOLUME?


(David Maze) #4

I’d double check this, but that all sounds correct.

It does an automatic -v /data even if you don’t explicitly specify it.


(Lcrespom) #5

Hello, I am experiencing the same head-scratching as @hyperknot: what good is a VOLUME command or its equivalent -v /data if the data will be lost after the container ends? It looks like a totally useless command, because it only works if you explicitly name the volume yourself, and in such case it will work even without the VOLUME command. So what difference does it make?


(Lcrespom) #6

I respond to myself: I see the --volumes-from parameter can be used when launching a second container, and it will automatically share all volumes from the first one. For example, if mysqlsvr is a container from the mysql image, which contains a VOLUME /var/lib/mysql command, then I can launch:

docker run --rm --volumes-from mysqlsvr ubuntu ls /var/lib/mysql

And it will show the contents of /var/lib/mysql from the mysqlsvr container.


(Lshchur) #7

So, to summarize.
All these statements are true for MacOS

– as you create docker containers, you cannot mount the volume directly on your OS’ filesystem

– instead, they’re mounted on an “interim” linux-based VM

– if you need to access your mounted volume, you create a container that is mounted to the volume you need (see the awesome answer above from crespom)