2

To make a change in the dependencies of a docker container, i'm runing docker-compose build. I want to update a dependency listed on requirements.txt to be more specific. But everytime that I execute this, it re-download and re-install all the requirements again instead of use existing wheels, even the satisfied requirements.

Am I missing something or is this the behavior by default? Is there a way change this behavior to make use of wheels created before?

The project was created with Django-Cookiecutter: docker=yes

This is my local.yml:

version: '3'

volumes:
  local_postgres_data: {}
  local_postgres_data_backups: {}

services:
  django:
    build:
      context: .
      dockerfile: ./compose/local/django/Dockerfile
    image: cctest_local_django
    depends_on:
      - postgres
    volumes:
      - .:/app
    env_file:
      - ./.envs/.local/.django
      - ./.envs/.local/.postgres
    ports:
      - "8000:8000"
    command: /start

  postgres:
    build:
      context: .
      dockerfile: ./compose/production/postgres/Dockerfile
    image: cctest_production_postgres
    volumes:
      - local_postgres_data:/var/lib/postgresql/data
      - local_postgres_data_backups:/backups
    env_file:
      - ./.envs/.local/.postgres

Dockerfile:

FROM python:3.6-alpine

ENV PYTHONUNBUFFERED 1

RUN apk update \
  # psycopg2 dependencies
  && apk add --virtual build-deps gcc python3-dev musl-dev \
  && apk add postgresql-dev \
  # Pillow dependencies
  && apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
  # CFFI dependencies
  && apk add libffi-dev py-cffi \
  # Translations dependencies
  && apk add gettext \
  # https://docs.djangoproject.com/en/dev/ref/django-admin/#dbshell
  && apk add postgresql-client

# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
RUN pip install -r /requirements/local.txt

COPY ./compose/production/django/entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint

COPY ./compose/local/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

WORKDIR /app

ENTRYPOINT ["/entrypoint"]
Cristianjs19
  • 765
  • 1
  • 9
  • 15
  • Will this dependency/package cause an error on the ***initial runtime (while running `runserver` command***? – JPG Sep 24 '19 at 05:06
  • COPY the exact requirements/local.txt before RUNning pip install rather than the entire requirements folder – Oluwafemi Sule Sep 24 '19 at 05:09
  • @JPG It happens with every change that I want to do, no matter what package is about. – Cristianjs19 Sep 24 '19 at 05:11
  • @OluwafemiSule Sorry I'm not sure to be understanding what you mean. The issue happens with every change that I make in requirements. – Cristianjs19 Sep 24 '19 at 05:20
  • 1
    I thought you refer to requirements installation happening every time you build the image. It's documented behaviour that changing the requirements file invalidates the build cache. https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache – Oluwafemi Sule Sep 24 '19 at 06:03
  • 2
    Making use of wheels build before can be done if you are sure you want this. Simply copy already build wheels to wheel cache before running pip. Interesting (for me overkill) solution around this: https://medium.com/@scythargon/cache-for-python-pip-downloads-and-wheels-in-docker-67f24e7cd84e – WiRai Sep 24 '19 at 07:06
  • @WiRai Yes, that is what I was looking for. Maybe in a easier way haha, but was that in fact. – Cristianjs19 Sep 24 '19 at 15:32
  • 2
    Crazy that there is no native way of doing this. – Rexcirus Dec 03 '19 at 20:50

0 Answers0