如何将命令行参数从oc startbuild传递到dockerfile,以在dockerfile内设置环境变量

2024-10-04 01:37:35 发布

您现在位置:Python中文网/ 问答频道 /正文

已使用以下命令,但Dockerfile中未传递环境值。 通过groovy脚本在oc容器中运行这些实例:

oc start-build -e environment=ipte2 ipte2-isell-api-7 --from-dir=./isell-python-wrapper --follow=true

**WARNING**: Specifying environment variables with binary builds is not supported.
Uploading directory "isell-python-wrapper" as binary input for the build ...
build "ipte2-isell-api-7-1" started
2)oc start-build --build-arg environment=ipte2 ipte2-isell-api-5 --from-dir=./isell-python-wrapper --follow=true

**WARNING**: Specifying build arguments with binary builds is not supported.
Uploading directory "isell-python-wrapper" as binary input for the build ...
build "ipte2-isell-api-5-1" started

error
Removing intermediate container f7ff031b18b1
Step 35/44 : COPY script/${environment}-local.conf /sum/lpp/ebb/local.conf
error: build error: lstat script/-local.conf: no such file or directory

Dockerfile

FROM wlp-base:0.1 #from statement base image
ARG environment

ENV environment=${environment}

COPY script/${environment}-local.conf

我需要在copy命令中传递上述环境值 如果我通过ENV environment=ipte2 直接在Dockerfile内部,工作正常。但是发送一个命令行参数,它无法得到它


Tags: fromdockerfilebuildapienvironmentlocalconfscript
2条回答

如果您使用docker cmd进行构建,则docker build arg将起作用。。 但我看到您正在使用OC容器。。因此,您需要向BuildArgs数组添加条目,该数组位于BuildConfig的dockerStrategy定义中

例如: 在我的项目中,我使用python yaml包生成BuildConfig.yaml文件…下面是代码

strategy_obj = {
            'dockerStrategy': {
                'from': {
                    'kind': 'ImageStreamTag',
                    'name': '{0}:{1}'.format(is_, tag_),
                    'namespace': project_
                },
                'buildArgs': [{'name': "env1",
                         'value': args[1]}]
            },
            'type': 'Docker'
        }

您也可以参考链接https://docs.openshift.com/container-platform/3.6/dev_guide/builds/build_strategies.html#docker-strategy-build-args

这在使用简单docker build build-arg environment=foo .时有效

我以前没有使用过oc,但是如果您找到一种像中那样指定build arg的方法 https://docs.openshift.com/container-platform/3.6/dev_guide/builds/build_strategies.html#docker-strategy-build-args

相关问题 更多 >