Reputation: 5906
In compose file version 1 , my docker-compose.yml is :
mongo:
image: mongo
volumes_from:
- mongodata
mongodata:
image: mongo
volumes:
- /home/dbdata/mongodb:/data/db
In localhost "/home/dbdata/mongodb" ,i saved some data . And it can be read through mongo container .
But i don't know how to update to compose file version 2. I have updated docker and docker-compose to the latest.
Docker version 1.10.2, build c3959b1
docker-compose version 1.6.2, build 4d72027
OS: ubuntu 15.10
I tried three ways ,but not working.
one : the compose file is :
version: '2'
services:
mongo:
image: mongo
volumes_from:
- mongodata
networks:
- wfij
mongodata:
image: mongo
volumes:
- /home/dbdata/mongodb:/data/db
# this is a spring cloud service , it can read mongo user data
useraccount:
image: user-account
networks:
- wfij
networks:
wfij:
driver: bridge
But the spring user-account service can't read the mongo data .
Another method: the compose file
-
version: '2'
services:
mongo:
image: mongo
volumes:
- mongo-data:/data/db
networks:
- wfij
useraccount:
image: user-account
networks:
- wfij
networks:
wfij:
driver: bridge
volumes:
mongo-data:
volumes: home/dbdata/mongodb
It not works again , the error is : "volumes is not supported" , but if i not set the volume container ,how can i mount the host directory "home/dbdata/mongodb" to the volume .
last , try this :
mongo:
image: mongo
volumes:
- mongo-data
voluems:
- mongo-data: /home/keryhu/dbdata/mongodb:/data/db
The error is :
ERROR: In file './docker-compose.yml', volume 'mongo-data' must be a mapping not a string.
Can help me ?
Upvotes: 2
Views: 7740
Reputation: 28140
version: '2'
services:
mongo:
image: mongo
volumes_from:
- mongodata
mongodata:
image: mongo
volumes:
- /home/dbdata/mongodb:/data/db
This should work. You don't have to make any changes for host volumes. It's only important for named volumes.
Upvotes: 1