Home > database >  (root) Additional property app is not allowed
(root) Additional property app is not allowed

Time:09-27

This is the docker-compose.yml and I didn't get this error until today. I didnt touch the .yml and the server runs as usual when I run it from Docker app.

app:
  build: .
  command: python -u app.py
  ports:
    - "5000:5000"
  volumes:
    - .:/app
  links:
    - db
db:
  image: mongo:latest
  hostname: dsairline_mongodb
  environment:
    - MONGO_INITDB_DATABASE=ds_airline_db
    - MONGO_INITDB_ROOT_USERNAME=root
    - MONGO_INITDB_ROOT_PASSWORD=pass
  volumes:
    - ./init-db.js:/docker-entrypoint-initdb.d/init-db.js:ro
  ports:
    - 27017:27017

CodePudding user response:

That looks like an obsolete version 1 Compose file. Recent versions of Compose have both removed support for this version of the file, and also declared the top-level version: key optional, so this file is now being interpreted as conforming to the Compose Specification, which it doesn't.

I'd recommend changing this file to use version 2 or 3 of the Compose format, which are supported by all current versions of the Compose tool. (Version 2 supports some options like resource constraints for standalone Docker installations; version 3 has several options only useful with Docker Swarm.) To update this file:

  • Add a top-level version: '2.4' or version: '3.8' line declaring the file format you're using.
  • Add a top-level services: block, and move all of this existing content under it.
  • Delete the obsolete links: option; the newer file formats automatically provide a Docker network that replaces Docker links.
version: '3.8' # or '2.4'      # add
services:                      # add
  app:
    build: .
    command: python -u app.py  # (delete? duplicates Dockerfile CMD)
    ports:
      - "5000:5000"
    volumes:                   # (delete? duplicates Dockerfile COPY)
      - .:/app
    # links:                   # delete, obsolete
    #   - db
  db:
    image: mongo:latest
    hostname: dsairline_mongodb
    environment:
      - MONGO_INITDB_DATABASE=ds_airline_db
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=pass
    volumes:
      - ./init-db.js:/docker-entrypoint-initdb.d/init-db.js:ro
      # - dbdata:/data/db      # add?
    ports:
      - 27017:27017
# volumes:                     # add?
#    dbdata:                   # add?

I also propose two other changes you might consider. Your MongoDB instance isn't configured to persist data anywhere; if you add a top-level volumes: block, you can create a named volume, which you can then add to the db service volumes: block. (This wasn't an option in the version 1 Compose file.) You also have options on your app container to overwrite the code in the image with a volume mount and override the Dockerfile's CMD, but these probably aren't necessary and you can also delete them.

  • Related