如何在docker-compose中定义build-args? [英] How to define build-args in docker-compose?

查看:141
本文介绍了如何在docker-compose中定义build-args?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下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 .

两个图像都将使用相同名称但值不同的build-args。另外,由于有数十个构建参数,将它们存储在组合服务特定的构建属性文件中会很方便。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆