I'm running docker within a container using the command below:
docker run --rm -ti --privileged -v /var/run/docker.sock:/var/run/docker.sock docker:1.12 sh
Within that container's shell I see a directory with a bunch of files. Let's say /project
with a filebuild.gradle
. I'd like to start a new container and mount this directory using the command below
docker run -ti --rm -v /project:/project openjdk:8-jdk bash -c "ls /project"
.
However it looks like the project directory is empty, the ls /project
does not show any files..
Now trying to mount a file:
docker run -ti --rm -v /project/build.gradle:/project/build.gradle openjdk:8-jdk bash -c "ls /project/"
This time the folder shows the file.
Anyone who has an idea why the volume mount does not work as expected. Is this a permission issue?
Best Answer
Nope. Inside the "docker" container, you only get a Docker client, not the whole thing. Once you mount the Docker socket inside your "docker" container, when you execute Docker commands, they go straight to the Docker "server" running on your actual Docker host. As such, that folder is expected to exist in your Docker Host.
Example how to mount a volume with docker in docker: