程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何在 docker-compose 子 Dockerfile FROM 子句中使用环境变量大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何在 docker-compose 子 Dockerfile FROM 子句中使用环境变量?

开发过程中遇到如何在 docker-compose 子 Dockerfile FROM 子句中使用环境变量的问题如何解决?下面主要结合日常开发的经验,给出你关于如何在 docker-compose 子 Dockerfile FROM 子句中使用环境变量的解决方法建议,希望对你解决如何在 docker-compose 子 Dockerfile FROM 子句中使用环境变量有所启发或帮助;

我正在使用 docker-compose 来构建一些 dockerfile。我正在使用环境变量 $IMAGE_TAG 来标记图像

  game-clIEnt:
    image: 09809809.dkr.ecr.us-east-1.amazonaws.com/crashgiants-web:${IMAGE_TAG}
    build:
      context: ..
      dockerfile: devops/clIEnt.Dockerfile
      args:
        - IMAGE_TAG=${IMAGE_TAG}
        - SIGNALHUB_HOST=crashgiants.io
        - SOCKETIO_HOST=crashgiants.io
        - TURNSERVER_HOST=crashgiants.io
        - ASSET_HOST=crashgiants.io
    ports:
      - "80:80"

我有一个带有 clIEnt.Dockerfile 子句的 dockerfile FROM,例如:

FROM 0809809708.dkr.ecr.us-east-1.amazonaws.com/crashgiants:$IMAGE_TAG as game-base

我可以将环境变量获取到 docker-compose 中,但不确定如何在子进程中使用它 clIEnt.Dockerfile

我正在使用以下命令调用撰写文件:IMAGE_TAG=local_tester docker-compose -f ./devops/docker-compose.yml build

这当前会引发错误

Building game-clIEnt

TraceBACk (most recent call last):
  file "compose/cli/main.py",line 67,in main
  file "compose/cli/main.py",line 126,in perform_command
  file "compose/cli/main.py",line 302,in build
  file "compose/project.py",line 468,line 450,in build_service
  file "compose/service.py",line 1147,in build
compose.service.buildError: (<service: game-clIEnt>,{'message': 'No build stage in current context'})

During handling of the above exception,another exception occurred:

TraceBACk (most recent call last):
  file "docker-compose",line 3,in <module>
  file "compose/cli/main.py",line 78,in main
TypeError: can only concatenate str (not "Dict") to str
[95080] Failed to execute script docker-compose

关于can only concatenate str (not "Dict") to str

解决方法

按如下方式修改您的 dockerfile:

ARG IMAGE_TAG=latest
FROM 0809809708.dkr.ecr.us-east-1.amazonaws.com/crashgiants:$IMAGE_TAG as game-base
ARG IMAGE_TAG

这会将 IMAGE_TAG 作为参数公开给图像。第二个 ARG IMAGE_TAG 是如果您想在映像构建中使用参数,因为 FROM 之前的参数将在不同的上下文中。

大佬总结

以上是大佬教程为你收集整理的如何在 docker-compose 子 Dockerfile FROM 子句中使用环境变量全部内容,希望文章能够帮你解决如何在 docker-compose 子 Dockerfile FROM 子句中使用环境变量所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。