In the context of docker I understand what layers of an image is and what's the uppermost writable layer. If I run docker container without any -v arguments will any volumes get created? If I do specify a volume (which is not a mount to some location in host) does the volume become this container's writable layer?
Volumes and image layers are separate concepts in Docker. To your first question, no, no volumes are created without -v
being used (ignoring for the moment the fact that the Dockerfile
format does have a VOLUME
verb).
If you specify a volume that is provided by any volume driver (the default being a local directory which will bind-mount into the target location in your container filesystem), this volume is unrelated to the image layers, including the 'writable' topmost layer provided by the back-end storage driver in use in your Docker engine.
Specifically, the storage driver in use is what controls how the layer stack, and that top "r/w" layer is managed. For example, the overlay or devicemapper or btrfs driver handles the mount of the image layers and creating and managing the top layer.
Volumes come into play outside of this by being bind-mounted in to existing (or created) paths within the filesystem image. When you exit the container, these volumes are preserved in their source location (e.g. for a local/default volume driver, in /var/lib/docker/volumes/<name>
) and the unmounted layer stack will have, under management of the storage driver in use, the modified "upper layer" of the layer stack, unless you had your container removed on exit (--rm
). These are two separately managed concepts and the volume system has no interplay with the storage backend driver.