Is there a way to list files inside a docker volume?

Remotec picture Remotec · Oct 21, 2017 · Viewed 9.7k times · Source

Simple question: Is there a docker command to view the files inside a volume?

I run docker for windows which creates a MobyLinuxVM on my machine to run Docker. I can't get a remote desktop connection onto this machine like I can with an Ubuntu VM (which I also have running on my machine).

Therefore, I can't see a way to see what is inside my host volumes (as they are actually inside the MobyLinuxVM), where as if I ran docker on my Ubuntu VM I could remote onto the machine and take a look.

Therefore, is there a way I can run some sort of docker volume command to list what's inside each volume?

Answer

BMitch picture BMitch · Oct 22, 2017

You can use a temporary container for this. I tend to use busybox for these temporary containers:

$ docker volume ls
DRIVER              VOLUME NAME
local               jenkins-home
local               jenkins-home2
local               jenkinsblueocean_jenkins-data
...

$ docker run -it --rm -v jenkins-home:/vol busybox ls -l /vol
total 428
-rw-r--r--    1 1000     1000           327 Jul 14  2016 com.dabsquared.gitlabjenkins.GitLabPushTrigger.xml
-rw-r--r--    1 1000     1000           276 Aug 17  2016 com.dabsquared.gitlabjenkins.connection.GitLabConnectionConfig.xml
-rw-r--r--    1 1000     1000           256 Aug 17  2016 com.nirima.jenkins.plugins.docker.DockerPluginConfiguration.xml
drwxr-xr-x   28 1000     1000          4096 Aug 17  2016 config-history
-rw-r--r--    1 1000     1000          6460 Aug 17  2016 config.xml
-rw-r--r--    1 1000     1000        174316 Jun  2 18:50 copy_reference_file.log
-rw-r--r--    1 1000     1000          2875 Aug  9  2016 credentials.xml
...

For a host volume, you can just replace the volume mount with the host directory name (fully qualified) in the docker run cli.

$ docker run -it --rm -v /path/on/host:/vol busybox ls -l /vol