【问题标题】:Docker Compose EnvironmentDocker 编写环境
【发布时间】:2018-07-31 09:21:52
【问题描述】:

我的 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 并添加 ENV 语句。

标签: docker docker-compose


【解决方案1】:

如果您希望在镜像中定义环境变量,则需要在 Dockerfile 中定义它们。您可以传递一个构建参数以允许您从撰写文件中更改该环境变量。

环境变量和其他设置,如命令和入口点,当在 compose 文件中设置时,适用于正在运行的容器。您需要运行 docker-compose updocker stack deploy ... 才能查看这些设置的结果。

请注意,开始不鼓励从 compose 运行构建。它们不再是第 3 版格式的功能,并且在您使用 compose 文件通过 swarm 模式等编排工具进行部署时不适用。理想的解决方案是使用推送到注册表的 CI 服务器进行构建。

【讨论】:

    猜你喜欢
    • 2021-01-23
    • 2021-09-18
    • 2018-12-16
    • 2017-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    相关资源
    最近更新 更多