How to install the django rest framework on docker

I have installed the following 3rd party libraries using the requirements.txt.
The content of the file is:

FROM python:3.7-slim

# Set environment varibles

ENV PYTHONDONTWRITEBYTECODE 1

ENV PYTHONUNBUFFERED 1

# Set work directory

WORKDIR /airproject

# Install dependencies

COPY requirements.txt /airproject/requirements

RUN pip install -r /airproject/requirements

# Copy project

COPY . /airproject/

And the requirements.txt is:

certifi==2019.3.9

chardet==3.0.4

Django==2.2.1

djangorestframework==3.9.2

idna==2.8

pytz==2019.1

requests==2.22.0

six==1.12.0

sqlparse==0.3.0

urllib3==1.25.2

I built the docker image without problems.

But whhen I run ā€˜docker-compose up’, it comes back with message, ModuleNotFoundError: No module named ā€˜rest_framework’. What should I do fix the problem?

5 years later, but…

I am not sure this Dockerfile is valid, but I had very similar problem and the solution was to use:
docker compose up --build
without ā€œā€“buildā€, compose is probably starting some old version of the image cached on your machine.

1 Like