0

如何访问 docker-compose 文件中的 entrypoint.sh 值。我已经声明了 entrypoint.sh 中的所有值,如下所示。我需要访问我的 docker-compose 文件中的那些

我使用 docker-volumes 将 entrypoint.sh 脚本复制到 docker 容器中的 /usr/local/bin 目录。

entrypoint.sh 脚本

MONGO_ROOT_USERNAME=root
MONGO_ROOT_PASSWORD=mongo@123
MONGO_EXPRESS_USERNAME=root
MONGO_EXPRESS_PASSWORD=express@123

码头工人撰写文件

mongo-express:
    image: mongo-express
    ports:
      - 8081:8081
    volumes:
      - "./docker-scripts/entrypoint.sh:/usr/local/bin"
    environment:
      ME_CONFIG_BASICAUTH_USERNAME: ${MONGO_EXPRESS_USERNAME}
      ME_CONFIG_BASICAUTH_PASSWORD: ${MONGO_EXPRESS_PASSWORD}
      ME_CONFIG_MONGODB_PORT: 27017
      ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_ROOT_USERNAME}
      ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_ROOT_PASSWORD}

但是当我运行 docker-compose -d 我收到这条消息

WARNING: The MONGO_ROOT_USERNAME variable is not set. Defaulting to a blank string.
WARNING: The MONGO_ROOT_PASSWORD variable is not set. Defaulting to a blank string.
WARNING: The MONGO_EXPRESS_USERNAME variable is not set. Defaulting to a blank string.
WARNING: The MONGO_EXPRESS_PASSWORD variable is not set. Defaulting to a blank string.
4

1 回答 1

1

你忘记导出你的环境变量:

export MONGO_ROOT_USERNAME=root
export MONGO_ROOT_PASSWORD=mongo@123
export MONGO_EXPRESS_USERNAME=root
export MONGO_EXPRESS_PASSWORD=express@123

更新1:

所以首先创建一个.env文件,然后将它添加到你的 docker compose

.env

MONGO_ROOT_USERNAME=root
MONGO_ROOT_PASSWORD=mongo@123
MONGO_EXPRESS_USERNAME=root
MONGO_EXPRESS_PASSWORD=express@123

然后在 docker-compose.yml

mongo-express:
    image: mongo-express
    ports:
      - 8081:8081
    volumes:
      - "./docker-scripts/entrypoint.sh:/usr/local/bin"
     env_file:  # <-- Add this line
      - .env    # <-- Add this line
    environment:
      ME_CONFIG_BASICAUTH_USERNAME: ${MONGO_EXPRESS_USERNAME}
      ME_CONFIG_BASICAUTH_PASSWORD: ${MONGO_EXPRESS_PASSWORD}
      ME_CONFIG_MONGODB_PORT: 27017
      ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_ROOT_USERNAME}
      ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_ROOT_PASSWORD}
于 2020-02-27T23:37:35.917 回答