ERROR: In file './docker-compose.yml', service 'volumes' must be a mapping not an array
Asked Answered
E

6

62

My docker-compose.yml looks like the below and I am trying to follow the compose file from the docker registry documentation here. When i run docker-compose up I get the below error.

ERROR: In file './docker-compose.yml', service 'volumes' must be a mapping not an array.

registry:
  restart: always
  image: sudarshan/registry
  ports:
    - 5000:5000
environment:
  REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt
  REGISTRY_HTTP_TLS_KEY: /certs/domain.key
  REGISTRY_AUTH: silly
  REGISTRY_AUTH_SILLY_SERVICE: SILLY_SERVICE
  REGISTRY_AUTH_SILLY_REALM: SILLY_REALM
volumes:
  - /usr/certs:/certs

My docker version is

Docker version 1.12.1, build 23cf638

docker-compose version is

docker-compose version 1.7.1, build 0a9ab35

Running on Ubuntu 16.04

EDIT:

Also tried

registry:
  restart: always
  image: sudarshan/registry
  ports:
    - 5000:5000
environment:
  REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt
  REGISTRY_HTTP_TLS_KEY: /certs/domain.key
  REGISTRY_AUTH: silly
  REGISTRY_AUTH_SILLY_SERVICE: SILLY_SERVICE
  REGISTRY_AUTH_SILLY_REALM: SILLY_REALM
volumes:
    - /usr/certs:/certs
Elmaleh answered 18/9, 2016 at 8:33 Comment(3)
Add two spaces before "- /usr/certs:/certs"Karrikarrie
Nope - I just tried that.Elmaleh
Ensure you gave directory names both side of "colon" (and) not a fileJemy
K
100

The thing is that you are not indenting the fields properly. Your docker-compose should look like the below:

registry:
  restart: always
  image: sudarshan/registry
  ports:
    - 5000:5000
  environment:
    REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt
    REGISTRY_HTTP_TLS_KEY: /certs/domain.key
    REGISTRY_AUTH: silly
    REGISTRY_AUTH_SILLY_SERVICE: SILLY_SERVICE
    REGISTRY_AUTH_SILLY_REALM: SILLY_REALM
  volumes:
    - /usr/certs:/certs
Kirkcudbright answered 18/9, 2016 at 9:26 Comment(0)
R
14

Mind the difference in syntax between the stanzas for each container, versus the listing of volumes and networks at the end:

<...snip...>
    volumes:
      - "database-volume:/var/lib/postgresql/data"    ## <---- dash !
    networks:
      - foo        ### <---- dash!
      - private    ### <----- dash!
volumes:
  foovol:      # NO dash!
  barvol:     # NO dash!
networks:
  baznetwork:    # NO dash!
  private:    # NO dash!
Ratio answered 26/8, 2021 at 12:27 Comment(0)
F
3

for me as a docker and yaml noob forget to add a tab it was like that :

volumes:
bundle_path:

it should be

volumes:
  bundle_path:

PS: it better to add yaml extension in your code editor

Fast answered 18/12, 2021 at 23:7 Comment(0)
H
2

I think that you must do lithe that :

version: '3'
services:
  web:
    stdin_open: true
    environment:
      - CHOKIDAR_USEPOLLING=true
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - '3000:3000'
    volumes:
      - /app/node_modules
      - .:/app
Hybrid answered 14/12, 2020 at 13:8 Comment(1)
the most important is : services: web: environment: - CHOKIDAR_USEPOLLING=trueHybrid
R
2

I was doing:

volumes:
   - myVolume: {}

But the correct was:

volumes:
    myVolume: {}
Rehearsal answered 28/4, 2022 at 22:32 Comment(0)
A
1

I had the same issue with services.db.environments. The fix was, using '=' instead of colon.

Like this:

   environment:
      - POSTGRES_USER=someuser
      - POSTGRES_PASSWORD=userpassword
      - POSTGRES_DB=mydb
Awe answered 19/10, 2021 at 22:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.