Reputation: 2566
I'm trying to use docker-compose. I started off by copying an example from the docker documentation:
version: '3'
services:
web:
image: nginx:alpine
ports:
- "80:80"
networks:
webnet:
volumes:
- type: volume
source: mydata
target: /data
volume:
nocopy: true
- type: bind
source: ./static
target: /opt/app/static
but what I get is: ERROR: In file './docker-compose.yml', volume must be a mapping, not an array.
It looks to me something to do with an old version of docker-compose. So I tried to update my docker running on MacOs, but it's up to date. By checking the version this is what I get:
Matteos-MacBook-Pro-2:chateo matteo$ docker-compose -v
docker-compose version 1.14.0, build c7bdf9e
shouldn't it be 1.17? I don't get it. Any hints?
I've tried to replace the array with a key:value list:
volumes:
mydata:
type: volume
source: mydata
target: /data
volume:
nocopy: true
static:
type: bind
source: ./static
target: /opt/app/static
But what I get is the following:
Matteos-MacBook-Pro-2:chateo matteo$ docker-compose build
ERROR: The Compose file './docker-compose.yml' is invalid because:
volumes.static value Additional properties are not allowed ('source', 'type', 'target' were unexpected)
volumes.mydata value Additional properties are not allowed ('volume', 'source', 'type', 'target' were unexpected)
Upvotes: 7
Views: 20695
Reputation: 1501
Using this syntax, the volume definition should be inside the service using it, see official documentation
version: "3.2"
services:
web:
image: nginx:alpine
volumes:
- type: volume
source: mydata
target: /data
volume:
nocopy: true
- type: bind
source: ./static
target: /opt/app/static
db:
image: postgres:latest
volumes:
- "/var/run/postgres/postgres.sock:/var/run/postgres/postgres.sock"
- "dbdata:/var/lib/postgresql/data"
volumes:
mydata:
dbdata:
Otherwise, you can declare a volume with specific driver like this:
version: "3.2"
volumes:
mydata:
driver: local
driver_opts:
o: uid=500,gid=500
Upvotes: 5
Reputation: 10185
Try to change volumes
definition to something like this:
volumes:
mydata:
type: volume
source: mydata
target: /data
volume:
nocopy: true
static:
type: bind
source: ./static
target: /opt/app/static
I can be wrong, but volumes cant be array.
Upvotes: 0