我如何执行shell命令来填充docker-compose build arg?

前端之家收集整理的这篇文章主要介绍了我如何执行shell命令来填充docker-compose build arg? 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在使用git commit hash git rev-parse –short HEAD进行版本控制,并希望将该值传递给我的docker映像.如何执行任意shell命令以在docker-compose.yml中填充构建arg?

---
version: '2'
services:
  my_app:
    build:
      args:
        - VERSION=EXECUTE_SHELL_COMMAND_HERE!!
...

我知道docs说我可以在运行时设置匹配的环境变量

VERSION=$(git rev-parse --short HEAD) docker-compose up

但是我正在寻找一种更清洁的方法,不需要每次都手动设置该环境变量.

@H_502_19@最佳答案
根据this docker compose issue,他们不支持

Sorry,this is not something we support. Usually,this is done by
setting environment variables and using variable substitution inside
the Compose file instead.

另一方面,这是2016年以来的问题,因此可能会过时…

猜你在找的Docker相关文章