Docker: Creating a data volume container vs simply using the -v flag with `run`?

I’m reading Docker’s user guide section on volumes at:

At the very first part it indicates how to create and add a volume to a container, this I will call “method 1”:

  • How to access web app live inside docker in docker
  • Docker on the mac separates internal and external file ownerships; not so on linux
  • Can not access kubernetes master from the container of pods according DNS
  • Remove /bin/busybox at build time
  • persist and share data from docker mongo container (with docker)
  • docker swarm 1.2.0 reschedule with port mapping
  • You can use the -v multiple times to mount multiple data volumes. Now, mount a single volume in your web application container.

    $ docker run -d -P --name web -v /webapp training/webapp python

    This will create a new volume inside a container at /webapp.

    Later on it goes to talk about Data volume containers, this I will call “method 2”:

    If you have some persistent data that you want to share between containers, or want to use from non-persistent containers, it’s best to create a named Data Volume Container, and then to mount the data from it.

    $ docker create -v /dbdata --name dbstore training/postgres /bin/true

    Here’s what I don’t get, what’s the difference between implementing a volume through simply using the -v command with docker run (method 1) v.s. implementing a volume by using a “Data volume container” (method 2)?

    It seems both ways you are just creating a volume that is persistent through the life of image’s non-persistent containers, correct me if I’m wrong.

  • Docker No MySQL connection to Nginx
  • Docker port binding error
  • How to access screen shots made in CI test on specific gitlab-runner
  • How to use multiple base images with Docker?
  • Using multer with express in docker container
  • How to add git repo path in the Dockerfile?
  • One Solution collect form web for “Docker: Creating a data volume container vs simply using the -v flag with `run`?”

    In my understanding, at least from docker 1.12 on, a volume is always the same thing: some persistant data stored somewhere on the host. But there are different ways to manage a volume:

    1. Create it and mount it to a container (your method 1). With this, you can use “volumes-from” when you want to mount volumes of one container into another container
    2. Create the volume using docker volume create, and let docker manage it. It will be saved somewhere on the host system (e.g. /var/lib/docker), but you don’t really care where and how exactly.
    3. Mount a host directory as a volume, in which case you know where it is mounted on your host and your are “responsible” for it.

    Then, there are “tricks” (as described here. For instance:

    “if you create a named volume by running a new container from image by docker run -v my-precious-data:/data imageName, the data within the container under /data will be copied into the named volume.”

    So the way you create/manage your volume might differ a bit, but it essentially always is a volume.

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