问题
Using Pipenv with Docker is causing some issues in my Django project.
I've installed Django locally with Pipenv which generates a Pipfile
and Pipfile.lock
. Then used startproject
to start a new Django project.
Then I add a Dockerfile
file.
# Dockerfile
FROM python:3.7-slim
ENV PYTHONUNBUFFERED 1
WORKDIR /code
COPY . /code
RUN pip install pipenv
RUN pipenv install --system
And a docker-compose.yml
file.
# docker-compose.yml
version: '3'
services:
web:
build: .
command: python /code/manage.py migrate --noinput && /code/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- 8000:8000
And run docker-compose up --build
to build the image and start the container. Everything works.
Now here's the issue...I want to add a new package, let's say psycopg2
so I can use PostgreSQL.
So...update my docker-compose.yml
to add PostgreSQL.
# docker-compose.yml
version: '3'
services:
db:
image: postgres
volumes:
- postgres_data:/var/lib/postgresql/data/
web:
build: .
command: python /code/manage.py migrate --noinput && /code/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- 8000:8000
depends_on:
- db
volumes: postgres_data:
And update the DATABASE
config in settings.py
.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'HOST': 'db',
'PORT': 5432
}
}
Now if I install psycopg2-binary
locally like pipenv install psycopg2-binary
this "should" sync with Docker. But I get "No module named 'psycopg2'` errors".
Ok so maybe I need to install it directly within Docker:
$ docker-compose exec web pipenv install psycopg2-binary`
Nope, same error.
Maybe I need to generate the lock file within Docker?
$ docker-compose exec web pipenv lock
Again no. So the issue is the state of Pipenv...I feel like I'm close but just not quite grasping something here.
Anyone see the error?
来源:https://stackoverflow.com/questions/53400385/django-docker-and-pipenv-error-adding-new-packages