将空字符串(双引号)参数传递给dockerfile

时间:2017-10-14 04:50:12

标签: docker build pecl

我的项目由Docker包装并在2个环境中运行:代理无代理

在这种情况下,我使用 php:apache 图像并通过pecl安装ext,所以我必须手动设置代理

FROM php:apache

RUN pear config-set http_proxy $http_proxy
# RUN pecl install mongodb && docker-php-ext-enable mongodb

$http_proxy arg将从docker-compose传递出2个值:http://server:port“”(双引号)

但是在“”的情况下构建自定义图像时,$http_proxy arg为null,并在config命令中显示错误

  

步骤4/4:RUN pear config-set http_proxy $ http_proxy

     

- >在19b69d089ff2中运行

     

config-set需要2或3个参数

1 个答案:

答案 0 :(得分:1)

由于它是RUN命令,您可以添加测试:

docker build -t my_apache .  --build-arg http_proxy=....

使用Dockerfile:

ARG http_proxy
RUN if [ "x$http_proxy" != "x" ] ; then  pear config-set http_proxy $http_proxy; fi 

您实际上不需要ARG http_proxy,因为它是one of the predefined ones