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?
Using also build time variables (–build-arg), you can add at the beginning (before
apt-get update
) apt proxy configuration:This is useful in the scenario you want to only cache packages from APT repositories
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
Dockerfile
is only 3 lines:And you just need to define build-time variables
http_proxy
and/orhttps_proxy
during image building: