I am new to docker. Learning it from a book called Learn Fundamentals of Docker 18.x From Packt Publishing. In the chapter on Docker Volume the author creates a vm using docker-machine and then creates a volume called my-data. I have executed the commands as below in first terminal window:
Then the author creates a container mounting that volume using -v command. I have executed the commands as below in a second terminal window):
When I try listing the files in that volume back in my first terminal window I get nothing.
So my understanding was
I also notice that the docker volume inspect my-data provides different mount points:
By this I understand they are different volumes, right?
But I am not seeing any data in the volume. Is my understanding correct? Can anybody explain to me how volumes in docker work?
Also I would like to know how do I navigate to this location from my Mac terminal?
Thanks in advance.
You are running docker-machine
which essentially creates a virtual machine on the host with the docker daemon installed. When you run docker volume create
in there, it creates the volume within the vm . I suspect you may be running the docker commands from outside of the docker-machine, but you have created the volume within the docker-machine, which is why they seem to be different volumes.
Ideally you want to configure your host to talk to the docker-machine when executing any docker commands. From the docs :
$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://172.16.62.130:2376"
export DOCKER_CERT_PATH="/Users/<yourusername>/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval "$(docker-machine env default)"
Otherwise, your understanding of docker volumes is correct. Docker volumes are created and managed by docker - meaning their physical location can change within the docker host. But data within the volume will always persist until you delete it. According to the docs :
When you create a volume, it is stored within a directory on the Docker host. When you mount the volume into a container, this directory is what is mounted into the container.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.