如何在 docker-compose 中定义 build-args? [英] How to define build-args in docker-compose?
问题描述
我有以下 docker-compose 文件
I have the following docker-compose file
version: '3'
services:
node1:
build: node1
image: node1
container_name: node1
node2:
build: node2
image: node2
container_name: node2
我可以构建两个图像并用一个命令启动它们
I can build both images and start them with a single command
docker-compose up -d --build
但我想在构建中使用 build-args.compose 范围之外的图像的原始构建脚本如下所示
But I would like to use build-args on the builds. The original build script of the image outside of the scope of compose looks something like this
#!/bin/sh
docker build
--build-arg ADMIN_USERNNAME_1=weblogic
--build-arg ADMIN_PASSWORD_1=weblogic1
--build-arg ADMIN_NAME_1=admin
--build-arg ...
--build-arg ...
-t test/foo .
两个图像都将使用名称相同但值不同的构建参数.此外,由于有数十个构建参数,将它们存储在组合服务特定的构建属性文件中会很方便.这可以通过 docker-compose 实现吗?
Both images would use build-args of the same name but different value. Also, as there are dozens of build args, it would be convenient to store them in a compose service specific build-properties file. Is this possible with docker-compose?
推荐答案
您可以直接在 docker-compose 文件中指定参数:
You can specify the arguments directly in your docker-compose file:
node1:
build: node1
args:
ADMIN_USERNNAME: weblogic1
ADMIN_PASSWORD: weblogic1
ADMIN_NAME: admin1
image: node1
container_name: node1
有关详细信息,请参阅官方文档.
See the official docs for details.
这篇关于如何在 docker-compose 中定义 build-args?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!