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

标签 docker docker-compose

我正在使用 git commit hash git rev-parse --short HEAD用于版本控制并希望将该值传递给我的 docker 镜像。如何执行任意 shell 命令来填充 docker-compose.yml 中的构建参数?

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

我知道 docs说我可以在运行时设置一个匹配的环境变量
VERSION=$(git rev-parse --short HEAD) docker-compose up

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

最佳答案

根据 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 - 如何执行 shell 命令来填充 docker-compose build arg?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47021562/

相关文章:

ubuntu - 无法从其他机器连接 cassandra 端口 9042。

docker - Cassandra官方指南docker start command network not working

docker - 将docker run命令转换为docker compose

amazon-web-services - 前端和后端应用程序的 Docker 示例

Dockerfile 无法复制文件。 ("cp"命令)

python - 在 gitlab-ci 中运行 Sonar 扫描仪

python - docker python 官方示例错误

docker - 使用 ansible-playbook 安装 docker-compose 时出错

docker - ElasticSearch 容器无法在 Docker 中启动

amazon-web-services - 无法在 K8S 集群中使用图像(在 ECR 中)