53

Trying to setup docker for the first time and I'm running into a problem with volumes. I feel pretty confident that the spacing and formatting in the .yml is correct at this point.

I've tried versions 3, 3.1, 3.2, 3.3 and 3.4. All are getting the same error message (below)

Unsupported config option for services.volumes: 'db2_prod'

version: '3'

services:
   liberty:
     image: liberty:${liberty_tag}
     ports:
       - "${liberty_ip}:9080:9080"
       - "${liberty_ip}:9443:9443"
     restart: always

   apache:
     image: webapp:${apache_tag}
     ports:
       - "${apache_ip}:80:80"
       - "${apache_ip}:443:443"
     restart: always

   db2:
     image: db2:${db2_tag}
     ports:
       - "${db2_ip}:50000:50000"
     stdin_open: true
     tty: true
     restart: always
     volumes:
       - db2_prod:/database/stagg3

   volumes:
     db2_prod:
Coy
  • 543
  • 1
  • 4
  • 10

2 Answers2

168

volumes needs to be at the same indentation with services i.e

services:
    #...
volumes:
    db2_prod:
stacksonstacks
  • 8,613
  • 6
  • 28
  • 44
  • 13
    For other folks landing here, you cannot have a space after the `:` inside the volumes. For example (bad: `- db2_prod: /database/stagg3` good: `- db2_prod:/database/stagg3`) – brthornbury Oct 18 '18 at 21:15
2
version: '3.7'
services:
    web:
        build: .
        command: python /code/manage.py runserver 0.0.0.0:8000
        volumes:
            - .:/code
        ports:
            - 8000:8000
        depends_on:
            - db
    db:
        image: postgres:11
        volumes:
            - postgres_data:/var/lib/postgresql/data/

volumes:
    postgres_data:

observe that version, services and volumes have same indent level. Moreover use spacebar for indentation, use of tab may create problem.