Mount docker host volume but overwrite with container's contents

Several articles have been extremely helpful in understanding Docker’s volume and data management. These two in particular are excellent:

  • http://container-solutions.com/understanding-volumes-docker/
  • http://www.alexecollins.com/docker-persistence/

However, I am not sure if what I am looking for is discussed. Here is my understanding:

  • SkyDNS in Daemon Sets and local DNS resolution
  • Docker images Ubuntu 14.04 not connected internet
  • docker compose 3 sysctls directive unsupported
  • Playframework: activator dist taking too long from within docker container
  • Java app in Docker container does not log to syslog properly
  • call a script file from one docker container to another container using --link container
    1. When running docker run -v /host/something:/container/something the host files will overlay (but not overwrite) the container files at the specified location. The container will no longer have access to the location’s previous files, but instead only have access to the host files at that location.
    2. When defining a volume in Dockerfile, other containers may share the contents created by the image/container.
    3. The host may also view/modify a Dockerfile volume, but only after discovering the true mountpoint using docker inspect. (usually somewhere like /var/lib/docker/vfs/dir/cde167197ccc3e138a14f1a4f7c....). However, this is hairy when Docker has to run inside a Virtualbox VM.

    My question is simple. How can I reverse the overlay so that when mounting a volume, the container files take precedence over my host files?

    I want to specify a mountpoint where I can easily access the container filesystem. But there just doesn’t seem to be anyone asking this question. I understand I can use a data container for this, or I can use docker inspect to find the mountpoint, but neither solution is a good solution in this case.

  • How can I make my dockerized Go program to use a dockerized Redis on default port?
  • Can I store npm scripts outside of package.json, to avoid forcing Docker to refresh all modules on any npm script update?
  • Dependent Containers and Links with IBM DevOps Services Build Pipeline
  • Passing Masked Jenkins Environment Variable to Docker container
  • Deployment methods for docker based micro services architecture on AWS
  • docker - connect over http to running container
  • One Solution collect form web for “Mount docker host volume but overwrite with container's contents”

    The docker 1.10+ way of sharing files would be through a volume, as in docker volume create.
    That means, you don’t need a container dedicated to a data volume, you can use a data volume directly.

    That way, you can share and mount that volume in a container which will then keep its content in said volume.
    That is more in line with how a container is working: isolating memory, cpu and filesystem from the host: that is why you cannot “mount a volume and have the container’s files take precedence over the host file”: that would break that container isolation and expose to the host its content.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.