How to solve “Unsupported config option for services.secrets” error after running docker-compose up?

After running the following command

sudo docker-compose up

I get this error message

ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.secrets: 'db_password'

docker-compose.yml

version: '3.7'
services:
  web:
    build: .
    command: npm start
    volumes:
      - ./src:/usr/app/
      - ./src/node_modules:/usr/app/node_modules
    ports:
      - 80:8080
    environment:
      DB_NAME: "testdb"
      DB_USER: /run/secrets/db_user
      DB_PASSWORD: /run/secrets/db_password
    secrets:
      - db_user
      - db_password
  db:
    build: mongo:latest
    volumes:
      - mongo:/data/db/
      - ./src/node_modules:/usr/app/node_modules
    ports:
      - "27017:27017"
    environment:
      MONGO_INITDB_DATABASE: "websitedb"
      MONGO_INITDB_ROOT_USERNAME_FILE: /run/secrets/db_user
      MONGO_INITDB_ROOT_PASSWORD_FILE: /run/secrets/db_password
    secrets:
      - db_user
      - db_password
  secrets:
    db_user:
      file: ./db_user.txt
    db_password:
      file: ./db_pass.txt

This is my Docker version :

Client:
 Version:           18.09.3
 API version:       1.39
 Go version:        go1.10.8
 OS/Arch:           linux/amd64
 Experimental:      false

I have already read several posts on this but I can’t solve it. Can anybody tell me what I am doing wrong?

Hi

Its because the “secrets” part is not suppose to go under the “services” part

Move “secrets” all the way to the left, and that will solve your problem

1 Like

This solved my problem. Thank you very much!