您需要使用构建时变量(–build-arg)。
该标志允许您传递在Dockerfile的RUN指令中像常规环境变量一样被访问的构建时变量。而且,这些值不会像ENV值那样保留在中间或最终图像中。
因此,您
Dockerfile只有3行:
ARG http_proxyARG https_proxyRUN apt-get update -y && apt-get -y install ...
您只需要定义构建时变量
http_proxy和/或
https_proxy在图像构建过程中:
$ docker build --build-arg http_proxy=http://<proxy_ip>:<proxy_port> --build-arg https_proxy=https://<proxy_ip>:<proxy_port> .



