如何访问我的 docker-compose 文件中的 entrypoint.sh 值?
How to access entrypoint.sh values in my docker-compose file?
如何访问 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
docker-编写文件
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.
您忘记导出环境变量:
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 撰写
.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}
如何访问 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
docker-编写文件
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.
您忘记导出环境变量:
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 撰写
.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}