My host server need a proxy to talk to the outside world. It's defined in env like http_proxy=http://10.10.123.123:8080 https_proxy=http://10.10.123.123:8080
.
I run an image tensorflow/tensorflow
, container named tf1
.
Inside tf1
(by exec into the container), I would like to install some package like grpcio and tensorflow-serving-api with pip, but fail with network error.
How can I use the proxy of the host inside the container? I have tried exec with -e
option but fail because of low version docker, so I don't know whether it works.
OS: CentOS 7.2, Docker:1.12.3
Helped for me to export the proxy settings in the same RUN
instruction just before the apt-get
in Dockerfile
FROM ubuntu
RUN export "http_proxy=http://host:port" \
&& export "https_proxy=http://host:port" \
&& apt-get update \
&& apt-get install -y SOME-PACKAGE
After that Ubuntu system in container was able to install the packages.
The noted way makes the proxy available only for this RUN
instruction.
If the whole image should use the proxy the ENV
instruction should be used:
FROM ubuntu
ENV http_proxy http://host:port
ENV https_proxy http://host:port
RUN apt-get update \
&& apt-get install -y SOME-PACKAGE
ENTRYPOINT [ "printenv" ]
Building the image $ docker image build -t test .
and running the container $ docker run test
will show that the proxy persist
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=8513fc1fb635
http_proxy=http://host:port
https_proxy=http://host:port
HOME=/root