Docker组合环境
我的docker-compose.yml如下所示Docker组合环境,docker,docker-compose,Docker,Docker Compose,我的docker-compose.yml如下所示 version: '3.4' services: identity.api: image: panda/identity.api build: context: . dockerfile: Services/Identity/PandaMarket.Identity.Api/Dockerfile ports: - "5000:80" environment:
version: '3.4'
services:
identity.api:
image: panda/identity.api
build:
context: .
dockerfile: Services/Identity/PandaMarket.Identity.Api/Dockerfile
ports:
- "5000:80"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ConnectionString=Server=sql.server;Database=PandaMarket.Identity;User Id=sa;Password=Password#123
当我执行docker compose build或docker compose up时我检查了docker inspect panda/identity.api,找不到ASPNETCORE\u环境&出现连接字符串 当我表演的时候
docker inspect -f '{{range $index, $value := .Config.Env}} {{$value}} {{end}}' panda/identity.api
我只能看到这些变量
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ASPNETCORE_URLS=http://+:80 DOTNET_RUNNING_IN_CONTAINER=true ASPNETCORE_VERSION=2.1.2
我的问题是环境如何反映在图像中?
如果希望在图像中定义环境变量,则需要在Dockerfile中定义它们。您可以传递一个build arg,以允许您从compose文件更改该环境变量 当在compose文件中设置时,环境变量和其他设置(如command和entrypoint)将应用于正在运行的容器。您需要运行
docker compose up
或docker stack deploy…
以查看这些设置的结果
请注意,开始不鼓励从compose运行生成。它们不再是版本3格式的一项功能,并且在使用编撰文件和编排工具(如swarm模式)部署时不适用。理想的解决方案是使用CI服务器构建,该服务器可推送到注册表。这是将添加到正在运行的容器中的环境变量。它们在图像中是未知的。当您检查容器时,您将看到它们,而不是图像。如果要将此环境变量放入映像中,则需要编写Dockerfile并添加ENV语句。