Docker data storage: Docker Volumes vs. Host Folders

I run a handful of Docker containers on a single Linux host. Docker containers are known to be replaced when they are rebuilt or swapped to a newer image version, losing all changed data. To permanently store certain folders of the container, they need to be swapped out via volumes or bind mounts. I usually have specific paths of the containers in defined folders connected to the host for this purpose (bind mounts). One of the reasons for using bind mounts instead of volumes is that I can more easily copy, backup or transfer the folders to another host via the host. But is this even the right approach? Would I be better off using Docker volumes? What is the advantage of Docker volumes?

Bind mounts

As mentioned earlier, bind mounts are defined folders of the host machine that are joined into specific directories of the Docker container. The host folder fits seamlessly in the Docker container's file system and behaves like any other folder in the container's file system. Data can be read and modified at the host folder.

Docker Volumes

Volumes are the recommended way to store Docker container data. Volumes are folders that are fully managed by Docker, which makes the storage independent of the underlying host and more secure. Docker volumes can be managed using Docker CLI commands or the Docker API.

Docker volumes vs. bind mounts

Advantages of volumes

  • Volumes are managed by Docker and are thus, just like containers: operating system independent.
  • Volumes can be managed using Docker CLI commands or the Docker API.
  • When using Docker Desktop on Windows or MAC, volumes deliver better performance.
  • The potential use of volume drivers and the associated options to store volumes on remote hosts or cloud providers and encrypt the content or add other functionality.
  • The content of Docker volumes can be pre-populated
  • According to the official Docker documentation, volumes are easier to back up or migrate than bind mounts:
    Volumes are easier to back up or migrate than bind mounts.
    Source: (retrieval date: 09/06/2022)
    In my opinion, this statement does not apply to every setup. When using volumes, access should no longer be directly through the host, making it difficult to use host commands such as rsync or another backup installed on the host. 


Use Docker volumes

When starting a container with docker run, volumes can be specified with the -v or -mount parameter:

docker run -v volumename:/app nginx:latest

When using --mount as a parameter, the properties are specified in a bit more detail:

docker run --mount source=volumename,target=/app nginx:latest

Docker Compose allows volumes to be defined in the volumes pane and specified in services as follows:


version: '3.1'

    image: test
      - volumename4service1:/var/www/html

    image: test2
      - volumename4service2:/var/www/html


For comparison: Use bind mounts

To use bind mounts instead of volumes, simply use a path in the local file system instead of the volume name. The path can be an absolute path or a relative path. Absolute paths start with "/" and are independent of the current folder in which the docker-compose file resides. Relative paths can be used with "./folder" name as a subfolder relative to the docker-compose.yml file:

File: docker-compose.yml

version: '3.1'

    image: test
      - /var/absolutefolderpath:/var/www/html

    image: test2
      - ./relativefolderpath:/var/www/html

Viewing volumes of a container: docker inspect

To find out which volumes or mounts a container uses, the command "docker inspect containername" can be used:

docker inspect wordpress


Where are Docker volumes located?

Volumes are stored in a folder in the host file system and managed by Docker (for Linux: /var/lib/docker/volumes/).

What is the difference between Docker volumes and bind mounts.

Both: Docker volumes and bind mounts link specific folders of a container to a folder on the host operating system. Bind mounts are defined folders on the host operating system, but for Docker Volumes, the path is managed by Docker. Docker volumes are also located in a folder on the host operating system, but the difference is that Docker predefines and manages the folder and enables the use of Docker CLI commands or the Docker API.

positive Bewertung({{pro_count}})
Rate Post:
{{percentage}} % positive
negative Bewertung({{con_count}})

THANK YOU for your review!

Updated: 2022-12-26 von Bernhard | Übersetzung Deutsch |🔔 | Comments:0

Docker commands in practice | Docker | Practice: Backup Docker container data: Volumes / Bind Mounts

Top articles in this section

Traefik: Forward traffic to another server

In preparation for moving my websites, I was looking for a way to simply forward all traffic from the old server to the new one.

Docker Swarm, Portainer and Traefik combined

As mentioned several times on this page, I primarily use the reverse proxy Traefik to access my Docker containers. To be able to manage the containers in a graphical GUI, I also use Portainer. For a single server, the setup fits so far, but if you want to deploy multiple servers, you can use Docker-Swarm for that. I first tested Portainer in combination with Swarm and extended the setup with Traefik including SSL with Let's Encrypt.

Practice: Backup Docker container data: Volumes / Bind Mounts

In my article "All Docker containers: Moving hosts, theory and practice", I already went a little bit into the topic of backup. If you followed the article, you know that I outsource the data of my Docker containers via bind mounts and back them up with rsync. The backup job is started via crontab. But first, I thought about what actually needs to be backed up when using Docker in a single-server setup.

Questions / Comments

By continuing to browse the site, you agree to our use of cookies. More Details