Reputation: 3433
I have a docker-compose.yml
file with some services:
version: '3'
services:
# PostgreSQL
db:
image: postgres:12
volumes:
- postgres_data:/var/lib/postgresql/data/
# MongoDB Server
mongo:
image: mongo:4.2
volumes:
- mongo_data:/data/db
- mongo_data:/data/configdb
volumes:
mongo_data:
mongo_config:
postgres_data:
I've been working in production starting the services with docker-compose up -d
. But now I want to use docker stack deploy --compose-file docker-compose.yml mystack
for future scalability.
The problem is that the services are now using new volumes. So I can't use all the DB data. How could I make Swarm to use the existing docker-compose
volumes?
Any kind of help would be really appreciated. Thanks in advance
Upvotes: 0
Views: 2877
Reputation: 3433
As Kiryl pointed out, the answer was the external volumes but there were several steps to follow, which I list below:
docker-compose.yml
file to add the external
key with the name of the existing volumes. The result was as follows:volumes:
mongo_data:
external:
name: existing name...
mongo_config:
external:
name: existing name...
postgres_data:
external:
name: existing name...
docker-compose up -d
to check that all the volumes are OK. Then shutdown with docker-compose down
docker stack deploy --compose-file docker-compose.yml mystack
Also, there's the same question in the official Docker Forum where there are other valuable solutions and opinions.
Upvotes: 4