出于某些原因,我必须在我的dockerfile中设置“http_proxy”和“https_proxy”ENV
。我想现在取消它们,因为还有一些构建过程无法通过代理完成。
# dockerfile
# ... some process
ENV http_proxy=http://...
ENV https_proxy=http://...
# ... some process that needs the proxy to finish
UNSET ENV http_proxy # how to I unset the proxy ENV here?
UNSET ENV https_proxy
# ... some process that can't use the proxy
根据docker docs,您需要使用shell命令:
FROM alpine
RUN export ADMIN_USER="mark" \
&& echo $ADMIN_USER > ./mark \
&& unset ADMIN_USER
CMD sh
有关详细信息,请参阅https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#env。
如果在构建图像期间需要env vars但它们不应该持久存在,那么就清除它们。在以下示例中,正在运行的容器显示空的env变量。
Dockerfile
# set proxy
ARG http_proxy
ARG https_proxy
ARG no_proxy
ENV http_proxy=$http_proxy
ENV https_proxy=$http_proxy
ENV no_proxy=$no_proxy
# ... do stuff that needs the proxy during the build, like apt-get, curl, et al.
# unset proxy
ENV http_proxy=
ENV https_proxy=
ENV no_proxy=
build.是
docker build -t the-image \
--build-arg http_proxy="$http_proxy" \
--build-arg https_proxy="$http_proxy" \
--build-arg no_proxy="$no_proxy" \
--no-cache \
.
润.是
docker run --rm -i \
the-image \
sh << COMMANDS
env
COMMANDS
产量
no_proxy=
https_proxy=
http_proxy=
...
AFAIK,Dockerfile中没有声明本身支持此功能。但是,您可以使用普通的shell命令取消设置 -
...
ENV http_proxy=http://...
RUN unset http_proxy
...