1 KiB
1 KiB
tags | created | |
---|---|---|
|
Sunday, May 04, 2025 |
Docker volumes
This is a WIP re-write of Docker Storage.
Bind mounts versus named volumes
Mostly when I use Docker in production I am using bind mounts rather than named volumes.
With bind mounts you explicitly map a path on the host to a path within the container. For example, in a Docker Compose:
services:
rocketchat:
volumes:
- /mnt/storagebox_alpha/rocketchat/mongo/db:/data/db
Here, the DB data for the RocketChat container is mapped to a drive in the
/mnt
directory on the actual server.
When you use bind mounts you do not need to include a volumes
section in the
Compose file.
In contrast named volumes let Docker manage the storage on the host. You
specify a name, but Docker decides where the data is stored. (Typically, this
will be in /var/lib/docker/volumes
.)
The equivalent to the previous example as a named volume:
services:
rocketchat:
volumes: rocketchat-db:/data/db
volumes:
rocketchat-db: