Search code examples
dockerdocker-composedocker-machine

Error: Additional property db-migrator is not allowed


When I run docker stack deploy -c docker-stack.yml myapp,

I'm getting error message:

db-migrator Additional property db-migrator is not allowed

docker-stack.yml:

version: "3"

services:
  web:
    image: tenzan/myapp_web:prod
    ports:
      - "80:3000"
    env_file:
      - .env/production/database
      - .env/production/web

  redis:
    image: redis

  database:
    image: postgres
    env_file:
      - .env/production/database
    volumes:
      - db_data:/var/lib/postgresql/data

volumes:
  db_data:

db-migrator:
  image: tenzan/myapp_web:prod
  command: ["./wait-for", "--timeout=300", "database:5432", "--", "bin/rails", "db:migrate"]
  env_file:
    - .env/production/database 
    - .env/production/web
  deploy:
    restart_policy:
      condition: none

Solution

  • db-migrator should be under services.

    You are using a YAML file and strucutre is important here.

    version: "3"
    
    services:
      web:
        image: tenzan/myapp_web:prod
        ports:
          - "80:3000"
        env_file:
          - .env/production/database
          - .env/production/web
    
      redis:
        image: redis
    
      database:
        image: postgres
        env_file:
          - .env/production/database
        volumes:
          - db_data:/var/lib/postgresql/data
    
      db-migrator:
        image: tenzan/myapp_web:prod
        command: ["./wait-for", "--timeout=300", "database:5432", "--", "bin/rails", "db:migrate"]
        env_file:
          - .env/production/database 
          - .env/production/web
        deploy:
          restart_policy:
            condition: none
    
    volumes:
      db_data: