44 lines
1 KiB
Markdown
44 lines
1 KiB
Markdown
---
|
|
tags: [docker]
|
|
created: Sunday, May 04, 2025
|
|
---
|
|
|
|
# Docker volumes
|
|
|
|
> This is a WIP re-write of [Docker Storage](./Docker_storage.md).
|
|
|
|
## _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:
|
|
|
|
```yml
|
|
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:
|
|
|
|
```yml
|
|
services:
|
|
rocketchat:
|
|
volumes: rocketchat-db:/data/db
|
|
|
|
volumes:
|
|
rocketchat-db:
|
|
```
|