I try to dockerise a django container for production.
So I have my dockerfile:
FROM python:3.8-alpine
ENV PATH="/scripts:${PATH}"
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers
RUN pip install -r /requirements.txt
RUN apk del .tmp
RUN mkdir /app
COPY ./Welzijn /app
WORKDIR /app
COPY ./scripts /scripts
RUN chmod +x /scripts/*
RUN mkdir -p /vol/web/media
RUN mkdir -p /vol/web/static
RUN adduser -D user
RUN chown -R user:user /vol
RUN chmod -R 755 /vol/web
USER user
CMD ["entrypoint.sh"]
and the docker-compose file:
version: "3.9"
services:
app:
build:
context: .
ports:
- "8000:8000"
volumes:
- ./Welzijn:/app
command: >
sh -c "python ./manage.py migrate &&
python ./manage.py runserver 0:8000"
environment:
- DEBUG=1
env_file:
- ./.env
and requirements.txt file:
Django>=4.0.4
uWSGI>=2.0.18,<2.1
djangorestframework>=3.13.1
psycopg2>=2.9.3
drf-spectacular>=0.22.1
Pillow>=9.1.0
drf-yasg==1.20.0
django-cors-headers==3.10.1
django-dotenv
But when I execute docker-compose up --build
I get this errors:
If you prefer to avoid building psycopg2 from source, please install the PyPI
3.686 'psycopg2-binary' package instead.
3.686
3.686 For further information please check the 'doc/src/install.rst' file (also at
3.686 <https://www.psycopg.org/docs/install.html>).
3.686
3.686 [end of output]
3.686
3.686 note: This error originates from a subprocess, and is likely not a problem with pip.
3.690 error: metadata-generation-failed
3.690
3.690 × Encountered error while generating package metadata.
3.690 ╰─> See above for output.
3.690
3.690 note: This is an issue with the package mentioned above, not pip.
3.690 hint: See above for details.
3.835
3.835 [notice] A new release of pip is available: 23.0.1 -> 23.2.1
3.835 [notice] To update, run: pip install --upgrade pip
------
failed to solve: process "/bin/sh -c pip install -r /requirements.txt" did not complete successfully: exit code: 1
Question: how to dockerise django for production?