I am not sure what you are actually asking. So I will try to provide some general information regarding docker
and proxy settings.
As you correctly mentioned:
I have created a Dockerfile, where the first line is: FROM python:2.7-slim
. This image is not in my local system, so it would download it from the repo.
Indeed when an image is not present in your host machine will be downloaded from an official docker repo(or private if you have set any).
In case you use a proxy you should provide docker daemon proxy settings. To achieve this follow these steps(quoted from official documentation):
Create a systemd drop-in directory for the docker service:
$ sudo mkdir -p /etc/systemd/system/docker.service.d
Create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY
environment variable:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
Flush changes
$ sudo systemctl daemon-reload
Restart docker
$ sudo systemctl restart docker
In this point I believe you will be able to download python:2.7-slim
image.
In the other hand if you want the proxy related environment variables to be set automatically within the container you should to follow this guide. Note that this is equivalent to my comment in your initial question. So by setting the proxy envs in the Dockerfile will not help you if the initial image(FROM
statement) is not present.
In conclusion, you can pre-configure your containers to have set up the proxy envs at runtime. But in a Dockerfile when you instruct the docker daemon to build an image,daemon should be aware of your proxy settings in order to download the image in FROM
statement if not present.
Hope it helps!