-1

This might be a simple question, but anyway.

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, right?

However, my proxy settings do not allow me to download the image. So, my question is, is there any chance I could declare the proxy settings in order to download the base image?

The host machine runs Ubuntu 16.04.

thanasissdr
  • 807
  • 1
  • 10
  • 26
  • A simple search would answer your question. Please specify your host's OS. – leopal Jul 20 '18 at 11:01
  • @leopal I have searched, but I haven't found any sufficient information. – thanasissdr Jul 20 '18 at 11:06
  • There is a similar question which might help: [Cannot download Docker images behind a proxy](https://stackoverflow.com/questions/23111631/cannot-download-docker-images-behind-a-proxy) – tgogos Jul 20 '18 at 11:08
  • @tgogos I have taken a look at this, but I need to modify system files. My question is if there is a way to declare the proxy settings with the docker file. – thanasissdr Jul 20 '18 at 11:10
  • 1
    @thanasissdr try this inside dockerfile ```ENV HTTP_PROXY your_proxy_address ENV HTTPS_PROXY your_proxy_address RUN export http_proxy=$HTTP_PROXY RUN export https_proxy=$HTTPS_PROXY``` . You should also edit your question to something more similar to this "My question is if there is a way to declare the proxy settings with the docker file" . – leopal Jul 20 '18 at 11:27
  • @leopal If my understanding is correct, ENV variables would be after the `FROM` statement. In that case, how am I going to download the base image? – thanasissdr Jul 20 '18 at 12:24

1 Answers1

0

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):

  1. Create a systemd drop-in directory for the docker service:

    $ sudo mkdir -p /etc/systemd/system/docker.service.d

  2. 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/"

  3. Flush changes

    $ sudo systemctl daemon-reload

  4. 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!

leopal
  • 4,711
  • 1
  • 25
  • 35