installing psycopg in alpine docker image

44 views Asked by At

I have the following dockerfile:

FROM python:3.12.0-alpine3.18

WORKDIR /usr/src/app

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN apk update && \
    apk add --virtual build-deps gcc python3-dev musl-dev && \
    apk add postgresql-dev


COPY requirements ./requirements
RUN pip install -r ./requirements/local.txt

COPY . .

EXPOSE 8000

Here is my requirements.txt:

Django==4.2.7
psycopg==3.1.13

The following error occurs when the image is loaded:

ERROR: failed to solve: process "/bin/sh -c pip install -r ./requirements/local.txt" did not complete successfully: exit code: 1

I tried to install various dependencies in my dockerfile. But always the same error.

What dependencies do I need to add to my dockerfile for psycopg to install? And also where can you read what dependencies you need to add and your dockerfile for certain libraries based on a certain image?

1

There are 1 answers

1
datawookie On

There seem to be some inconsistencies in the paths used in your Dockerfile. Please try the following using your current requirements.txt:

FROM python:3.12.0-alpine3.18

WORKDIR /usr/src/app

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN apk update && \
    apk add --virtual build-deps gcc python3-dev musl-dev && \
    apk add postgresql-dev

COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .

EXPOSE 8000

Below you can see the image builds successfully and you can load both packages in Python.

enter image description here