I am behind a proxy an i need to install something via apt-get.
The best I came with is this
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.
Any idea how to do it in less then 5 layers?
You need to use build-time variables (–build-arg).
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.
So, your
Dockerfileis only 3 lines:And you just need to define build-time variables
http_proxyand/orhttps_proxyduring image building: