I do not have a clear vision about how to populate named volume in Swarm. I am wondering what are the best practices for named volume, since this now replaces the deprecated data-only containers (DOC) (said by docker member, since feb 2016, source here). The official doc https://docs.docker.com/engine/tutorials/dockervolumes/ stills talk about data-only containers, but shouldn’t (or at least it should write DOC are deprecated).
My use-case is that I will have a Swarm cluster (old Swarm mode for now, Swarm mode later), I will run containers there, and attach to them configuration files in either a DOC or named volume.
- With DOC:
I planned for this to put these files from our SCM (git) in a data-only container, put them in a registry, then running this DOC from registry in the cluster, next to the main container, and using “–volume-from”.
For eg: the docker run command would
docker run -d --name Config configfileforHttpd
docker run --volume-from Config httpd
- Without DOC:
I would have to describe an external volume in docker-compose.yml, and I suppose I have to create a compose file, with a named volume first, and somehow put the configuration files inside. The origin of these files should be in another container (not technically a DOC), and I will do a
docker run -v [named_volume]:/path/to/volume/internal myimage cp -rf /files /path/to/volume/internal