I'm trying to install a simple Django package in a Docker container.
Here is my dockerfile
FROM python:3.8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY Pipfile Pipfile.lock /app/
RUN pip install pipenv && pipenv install --system
COPY . /app/
And here is my docker-compose:
version: '3.7'
services:
web:
build: .
command: python /app/manage.py runserver 0.0.0.0:8000
volumes:
- .:/app
ports:
- 8000:8000
depends_on:
- db
db:
image: postgres:11
volumes:
- /Users/ruslaniv/Documents/Docker/djangoapp:/var/lib/postgresql/data/
environment:
- POSTGRES_USER=XXX
- POSTGRES_PASSWORD=XXX
- POSTGRES_DB=djangoapp
volumes:
djangoapp:
So, I start my container with
docker-compose up
then install a package and rebuild an image
docker-compose exec web pipenv install django-crispy-forms
docker-compose down
docker-compose up -d --build
Then I add 'crispy_forms'
into local settings.py
and register crispy forms tags in a local html file with {% load crispy_forms_tags %}
and then use them for the form with {{ form|crispy }}
But the form is not rendered properly.
Since the package itself and its usage are very simple I think there is a problem with installing the package in a container.
So the question is how to properly install a Django package in a Docker container and am I doing it properly?
Although the question was about installing Django packages in a Docker container, the solution was much simpler.
The two facts I should have paid closer attention to:
django-crispy-forms
inside a container, I could see appropriate entries appearing in local Pipfile
and Pipfile.lock
(hat tip to @MichalKrejčí)ModuleNotFoundError: No module named 'crispy_forms'
All that meant that the package was installed successfully and there was something else going on.
Which was the fact that I had to manually include Bootstrap4 CSS files for crispy-forms to render forms according to a Bootstrap4 template.