I'm building my containers with docker-compose
and I would like to use the new volume API from Docker, but I don't see how to.
I want to be able to say docker-compose up -d
to:
- Create a volume, or use it if already created.
- Create services containers with data from previous volume container.
First of all you must be using a version 2 Compose file to use the new specifications for creating and using named volumes. The Compose File Reference includes all you need to know, including examples.
To summarize:
version: '2'
to the top ofdocker-compose.yml
.services:
key.volumes:
key.volumename:/path
wherevolumename
is the name given under thevolumes:
key (in the example below it isdbdata
) and/path
is the location inside the container of the mounted volume (e.g.,/var/lib/mysql
).Here's a minimal example that creates a named volume
dbdata
and references it from thedb
service.