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:
- 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_ENVIRONMENT & ConnectionString 出现。
当我表演时
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 中定义它们。您可以传递构建参数以允许您从撰写文件中更改该环境变量。
环境变量和其他设置(如命令和入口点)在 compose 文件中设置后,将应用于正在运行的容器。您将需要运行docker-compose up
或docker stack deploy ...
查看这些设置的结果。
请注意,开始不鼓励从 compose 运行构建。它们不再是第 3 版格式的功能,并且在您使用 compose 文件通过 swarm 模式等编排工具进行部署时不适用。理想的解决方案是使用推送到注册表的 CI 服务器进行构建。
推荐阅读
- python - rpy2下的立体回归:“下标越界”错误
- r - 如何按 R data.table 中的不同列分组?
- python - 为什么python函数执行什么也没给我
- linux - 为什么Linux信号总是由主线程处理?
- c# - 如何在 Inspector 中设置 GUI.Button 的位置?
- c++ - 如何使用 opencv 转到视频中的特定时间?
- php - 更新 SQL 数据库列会更新具有相同数据的所有行
- java - 我可以完全用一种跨平台语言开发一个多平台项目-windows/Android-吗?
- python - 为什么 all() 为空的可迭代对象返回 True?
- html - Github Pages 在一个站点上显示嵌入的 YouTube 视频,但在另一个站点上不显示,有解决办法吗?