在Dockerfile中使用代理运行apt-get [英] run apt-get with proxy in Dockerfile

查看:216
本文介绍了在Dockerfile中使用代理运行apt-get的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代理后面,我需要通过apt-get安装某些东西.

I am behind a proxy an i need to install something via apt-get.

我最喜欢的是这个

ARG PROXY
ENV http_proxy=$PROXY
ENV https_proxy=$PROXY
RUN apt-get update -y && apt-get -y install ...
ENV http_proxy=
ENV https_proxy=

问题是我之后需要取消设置这些环境变量.

The thing is that I need to unset those environment variables afterwards.

有没有想法在不到5层的时间内做到这一点?

Any idea how to do it in less then 5 layers?

推荐答案

您需要使用

You need to use build-time variables (–build-arg).

此标志允许您传递在Dockerfile的RUN指令中像常规环境变量一样访问的构建时变量.而且,这些值不会像ENV值那样保留在中间或最终图像中.

This flag allows you to pass the build-time variables that are accessed like regular environment variables in the RUN instruction of the Dockerfile. Also, these values don’t persist in the intermediate or final images like ENV values do.

因此,您的Dockerfile只有3行:

ARG http_proxy
ARG https_proxy
RUN apt-get update -y && apt-get -y install ...

您只需要在图像构建过程中定义构建时变量http_proxy和/或https_proxy:

And you just need to define build-time variables http_proxy and/or https_proxy during image building:

$ docker build --build-arg http_proxy=http://<proxy_ip>:<proxy_port> --build-arg https_proxy=https://<proxy_ip>:<proxy_port> . 

这篇关于在Dockerfile中使用代理运行apt-get的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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