mongo-express 不是以 docker-compose 文件开头

mongo-express is not starting with docker-compose file

下面是我的 docker-compose.yml 文件。

version: '3.1'
services:
  mongodb:
    image: mongo
    ports: 
      - 27017:27017
    environment:
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=admin
  mongo-express:
    image: mongo-express
    ports:
      - 8081:8081
    environment:
      - ME_CONFIG_MONGODB_ADMINUSERNAME=root
      - ME_CONFIG_MONGODB_ADMINPASSWORD=admin
      - ME_CONFIG_MONGODB_SERVER=mongodb
    depends_on:
      - mongodb
    restart: on-failure

我遇到错误:

Could not connect to database using connectionString: mongodb://root:admin@mongodb:27017/" in mongo-express. PFA-1 The root user is created after error shown in mongo-express. PFA-2 is the issue because mongo-express executed before mongodb?

这是我的代码,它工作正常:

    mongo:
      image: mongo
      environment:
         MONGO_INITDB_ROOT_USERNAME: root
         MONGO_INITDB_ROOT_PASSWORD: admin
      ports:
         - 27017
      volumes:
         - mongodb_data_container:/data/db
      command: mongod --port 27017 --auth
    
    mongo-express:
        image: mongo-express
        ports:
          - 8081:8081
        environment:
          ME_CONFIG_MONGODB_ADMINUSERNAME: root
          ME_CONFIG_MONGODB_ADMINPASSWORD: admin

对我来说,正是这一部分让 mongo 快速开始:

mongo-express:
    image: mongo-express
    restart: always
    ...