Question

I am trying to build an image for my flask based web-application using docker build. My Dockerfile looks like this:

FROM beehive-webstack:latest
MAINTAINER Anuvrat Parashar <anuvrat@zopper.com>

EXPOSE 5000
ADD . /srv/beehive/

RUN pip install -i http://localhost:4040/root/pypi/+simple/ -r /srv/beehive/requirements.txt

pip install without the -i flag works, but it downloads everything from pypi which, naturally is slow.

The problem is that pip does not access the devpi server running on my laptop. How can I go about achieving that?

Was it helpful?

Solution

localhost refers to the docker container, not to your host as RUN lines are just executed commands in the container. You thus have to use a network reachable IP of your laptop.

Con: This makes your Dockerfile unportable, if others don't have a pypi mirror running.

OTHER TIPS

One answer is a devpi helper container. You start docker devpi image and have it expose port 3141. Then you can add this as an extra source for pip install using environmental variables in your docker file.

Starting devpi using docker compose:

devpi:
  image: scrapinghub/devpi
  container_name: devpi
  expose:
      - 3141
  volumes:
      - /path/to/devpi:/var/lib/devpi

myapp:
  build: .
  external_links:
   - devpi:devpi

docker-compose up -d devpi

Now you need to configure the client docker container. It needs pip configured:

In your Dockerfile: ENV PIP_EXTRA_INDEX_URL=http://devpi:3141/root/pypi/+simple/ \ PIP_TRUSTED_HOST=devpi

Check it's working by logging into your container:

docker-compose run myapp bash

pip install --verbose nose

Output should include

  2 location(s) to search for versions of nose:
  * https://pypi.python.org/simple/nose/
  * http://devpi:3141/root/pypi/+simple/nose/

Now you can upload packages to your container either from another container or sftp.

This approach has the advantages of speeding builds but not breaking them if the devpi container is not present.

Notes: Don't publish ports to devpi without a strong password as it's a security issue. People could use it to upload arbitrary code which you application would install and execute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top