I'm following allong with the book 'Django for Professionals' but I run into what seems like the same problem the author of the book experienced in this quastion. I'm using it on windows so with Docker-toolbox and what seems to happen is that after running
docker-compose exec web pipenv install psycopg2-binary==2.8.4
the Pipfile.lock has changed inside the container, but it doesn't transfer/sync this to my local files, it seems as if the 'volume' lost track of the file?
I opened the Pipfile.lock inside the container to verify that it indeed added psycopg2, which it did, but when I docker-compose down
it is not in my local Pipfile.lock and thus lost the next time when I use docker-compose up -d --build
The only solution I have found myself so far is to copy the file over from the running docker container to my local folder with which is far from ideal
docker cp web:/code/Pipfile.lock .
output from docker-compose exec web pipenv install psycopg2-binary==2.8.4
E:\Documenten\websites\code\postgresql>docker-compose exec web pipenv install
psycopg2-binary==2.8.4
Installing psycopg2-binary==2.8.4…
Adding psycopg2-binary to Pipfile's [packages]…
✔ Installation Succeeded
Installing dependencies from Pipfile.lock (a06fa0)…
▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 5/5 — 00:00:09
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
docker-compose.yml
version: '3.7'
services:
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- 8000:8000
depends_on:
- db
db:
image: postgres:11
environment:
- "POSTGRES_HOST_AUTH_METHOD=trust"
Dockerfile
# Pull base image
FROM python:3.7-slim
# Set environment variables
ENV PYTHDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set work directory
WORKDIR /code
# Install dependencies
COPY Pipfile Pipfile.lock /code/
RUN pip install pipenv && pipenv install --system
# Copy project
COPY . /code/
# Make executable
RUN chmod +x /code/manage.py