Docker: pg_config executable not found in docker? [duplicate] - python

This question already has answers here:
pg_config executable not found
(54 answers)
Closed 6 months ago.
i am trying to use docker in my django project, i am new to using docker and i do not really know where the error is coming from.
This is how my Dockerfile looks:
FROM python:3.8.13-slim-buster
WORKDIR /app
COPY ./my_app ./
RUN pip install --upgrade pip --no-cache-dir
RUN pip install psycopg2 --no-cache-dir
RUN apk del build-deps --no-cache-dir
RUN pip install -r /app/requirements.txt --no-cache-dir
RUN \
apk add --no-cache postgresql-libs && \
apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev && \
python3 -m pip install -r requirements.txt --no-cache-dir && \
apk --purge del .build-deps
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
# CMD ["gunicorn", "main_app.wsgi:application", "--bind"]

Hopefully you already know that:
pg_config is in postgresql-devel (libpq-dev in Debian/Ubuntu, libpq-devel on Centos/Fedora/Cygwin/Babun.)

Related

pip install -r requirements.txt failing: does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found

Getting an error when build docker image:
FROM python:3.9
RUN apt-get update
COPY requirements.txt /tmp/
RUN pip install --upgrade pip && \
pip install -r /tmp/requirements.txt
COPY . /tmp/
ERROR:
file:/// (from -r /tmp/requirements.txt (line 2)) does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found
And
FROM python:3.9 as base
RUN apt-get update
COPY . /tmp/
RUN pip install --upgrade pip && \
pip install -r /tmp/requirements.txt
Gives the same result
While if I start from Ubuntu as base:
FROM ubuntu:20.04 as base
ENV TZ=Europe/Moscow
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update && \
apt-get install -y \
python3.9 \
python3.9-dev \
python3-pip \
python3.9-venv \
python3-psycopg2 \
git && \
python3.9 -m pip install pip --upgrade
COPY . /app/
RUN ln -sf /usr/bin/python3.9 /usr/bin/python
WORKDIR /app
RUN pip install --no-cache-dir -r requirements.txt
RUN apt-get update
ENV WORKSPACE /app
everything builds fine
but if I copy requirements first
COPY requirements.txt /app/
RUN pip install -r /app/requirements.txt
it gives the same error as before:
ERROR:
file:/// (from -r /app/requirements.txt (line 2)) does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.

pip install of aws-sam-cli package with python3.7 version

In the below docker file:
FROM alpine:latest
ENV HOME /home/samcli
ENV PATH $HOME/.local/bin:$PATH
RUN mkdir /root/bin /aws; \
apk add --no-cache groff less bash python jq curl py-pip tzdata
RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN apk add --no-cache --virtual .build-deps gcc python2-dev python3-dev linux-headers musl-dev && \
pip install --upgrade pip; \
adduser samcli -Du 5566; \
chown -R samcli $HOME;
USER samcli
WORKDIR $HOME
RUN pip install --user --upgrade awscli aws-sam-cli;
USER root
RUN apk del .build-deps; \
rm -rf /var/cache/apk/*
Layer(RUN pip install --user --upgrade awscli aws-sam-cli;) is installing with python 2.7, despite image has python3.7 installed.
I see below deprecation error when installing python package:
Step 9/11 : RUN pip install --user --upgrade awscli aws-sam-cli;
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/
How to install aws package with python3.7?
because below command is using python2
pip install --user --upgrade awscli aws-sam-cli;
I would recommend using python offical image based on alpine so you will do not need to maintain and install the python version. Below base image is base on alpine 3.9 and python version is 3.7
FROM python:3.7-alpine3.9
ENV HOME /home/samcli
ENV PATH $HOME/.local/bin:$PATH
RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN apk add --no-cache --virtual .build-deps python2-dev python3-dev gcc linux-headers musl-dev && \
adduser samcli -Du 5566; \
chown -R samcli $HOME;
RUN apk add --no-cache groff less bash jq curl py-pip tzdata
USER samcli
WORKDIR $HOME
RUN pip install --user --upgrade awscli aws-sam-cli;
USER root
RUN apk del .build-deps; \
rm -rf /var/cache/apk/*
This Dockerfile works for me.
FROM alpine:latest
RUN apk update && apk upgrade
RUN apk --no-cache add python3 py3-pip gcc musl-dev python3-dev
RUN pip install aws-sam-cli awscli
...

ERROR: unsatisfiable constraints - Docker

When I install Python project, I get this error with Docker. I did not find a solution despite researching on the google. By the way When I run project on Docker, how to display on browser ?
test#test-VirtualBox:~/backend$ sudo docker build -t test .
Sending build context to Docker daemon 489kB
Step 1/11 : FROM python:3.6-alpine
---> 267db919e15e
Step 2/11 : RUN addgroup -S app && adduser -S -g app app
---> Using cache
---> ce1632a22469
Step 3/11 : WORKDIR /usr/src/app
---> Using cache
---> 01b36ea9b7c1
Step 4/11 : RUN apk --update --upgrade add --virtual deps gcc python3-dev linux-headers musl-dev alpine-sdk openssl-dev gmp-dev libffi-dev postgresql-dev && apk --update --upgrade add --no-cache libpq gmp
---> Running in d962dfc4a26a
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
openssl-dev-1.0.2o-r2:
conflicts:
libressl-dev-2.7.4-r0[pc:libcrypto=1.0.2o]
libressl-dev-2.7.4-r0[pc:libssl=1.0.2o]
libressl-dev-2.7.4-r0[pc:openssl=1.0.2o]
libressl-dev-2.7.4-r0:
conflicts:
openssl-dev-1.0.2o-r2[pc:libcrypto=2.7.4]
openssl-dev-1.0.2o-r2[pc:libssl=2.7.4]
openssl-dev-1.0.2o-r2[pc:openssl=2.7.4]
satisfies:
postgresql-dev-10.5-r0[libressl-dev]
deps-0:
masked in: cache
satisfies: world[deps]
The command '/bin/sh -c apk --update --upgrade add --virtual deps gcc python3-dev linux-headers musl-dev alpine-sdk openssl-dev gmp-dev libffi-dev postgresql-dev && apk --update --upgrade add --no-cache libpq gmp' returned a non-zero code: 4
Dockerfile:
FROM python:3.6-alpine
RUN addgroup -S app && adduser -S -g app app
WORKDIR /usr/src/app
RUN apk --update --upgrade add --virtual deps \
gcc python3-dev linux-headers musl-dev \
alpine-sdk gmp-dev libffi-dev \
postgresql-dev && \
apk --update --upgrade add --no-cache libpq gmp
COPY ./requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
RUN apk del deps
COPY . /usr/src/app
RUN chown -R app:app /usr/src/app
USER app
EXPOSE 8080
Why do you need to install openssl-dev package? Alpine packages are compiled with libressl. You can't install both openssl-dev and libressl-dev in container with alphine 3.6.
I've met the same problem. Our company build a base image based on python:2.7-alpine, but maybe it is too old. So don't install openssl-dev is not enough.
Look this :
satisfies:
postgresql-dev-10.5-r0[libressl-dev]
postgresql-dev rely on libressl-dev, so I delete openssl-dev firstly:
RUN apk del openssl-dev
Then everything is ok.

Error when installing python3 packages in alpine

I am currently building an image from alpine:3.7.
There are two packages that I am having problems with:
pendulum (specifically python-dateutils package)
service_identity (specifically attrs package)
The error that I receive it is:
Could not find a version that satisfies the requirement setuptools (from versions: ) No matching distribution found for setuptools
Note: all packages are pre-cached on a directory using pip download.
The dockerfile looks as follows:
RUN apk add --no-cache --virtual .build-deps <dev packages>
&& apk add --no-cache --update python3
&& pip3 install --upgrade pip setuptools
RUN pip3 install -f ./python-packages --no-index -r requirements.txt ./python-packages/pkgs
....
dev-packages such as libffi-dev, libressl-dev, etc.
I'm not sure about the full list of dev-packages to build in the question, but it should be the following: g++ (GNU C++ standard library and compiler), python3-dev (python3 development files), libffi-dev (libffi development files) and openssl-dev (Toolkit for SSL v2/v3 and TLS v1 development files).
The Dockerfile is:
FROM alpine:3.7
RUN apk add --no-cache --virtual .build-deps g++ python3-dev libffi-dev openssl-dev && \
apk add --no-cache --update python3 && \
pip3 install --upgrade pip setuptools
RUN pip3 install pendulum service_identity
Apparently when upgrading pip with:
pip3 install --upgrade pip setuptools
I removed pip upgrading and installation worked. Now, I have been researching the correct way to upgrade pip on alpine and found a Dockerfile in a github repo that does this check:
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
Which makes sure that pip3 is being referred when calling just pip command by doing a symbolic link on python and system binaries' directories.

Python docker build up error

I got this error when i run command
sudo docker-compose up
Docker File:
FROM alpine
ARG AWS_RDS_USER
ARG AWS_RDS_PASSWORD
ARG AWS_RDS_HOST
ARG AWS_RDS_DATABASE
ARG LOCALE_SERVICE_URL
ARG CRYPTO_KEY
ENV APP_DIR=/app
ENV APP_ENV=production
ENV DATABASE_CONNECTION_STRING=mysql://${AWS_RDS_USER}:${AWS_RDS_PASSWORD}#${AWS_RDS_HOST}/${AWS_RDS_DATABASE}
ENV LOCALE_SERVICE_URL=$LOCALE_SERVICE_URL
ENV CRYPTO_KEY=$CRYPTO_KEY
COPY build/requirements.txt build/app.ini ${APP_DIR}/
COPY build/nginx.conf /etc/nginx/nginx.conf
COPY api ${APP_DIR}/api
RUN apk add --no-cache curl python pkgconfig python-dev openssl-dev libffi-dev musl-dev make gcc
RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python
RUN apk update && \
apk add --virtual .build-deps autoconf gcc make g++ python-dev && \
apk add nginx uwsgi uwsgi-python py2-pip py-mysqldb && \
chown -R nginx:nginx ${APP_DIR} && \
chmod 777 /run/ -R && \
chmod 777 /root/ -R && \
pip2 install --upgrade pip && \
pip2 install -r ${APP_DIR}/requirements.txt && \
apk del .build-deps && \
rm -fR tmp/* && \
pw_migrate migrate --database=$DATABASE_CONNECTION_STRING --directory=$APP_DIR/api/migrations -v
EXPOSE 80
CMD nginx && uwsgi --ini ${APP_DIR}/app.ini
For solution, I tried to install below packages
1) gcc package.
2) libffi packages.
3) pip openssl packages.
But still error is not resolved. Any help should be appreciated
Try the solution suggested here
This is because you need a working compiler, the easiest way around
this is too install the build-base package like so:
apk add --no-cache --virtual .pynacl_deps build-base python3-dev
libffi-dev This will install various tools that are required to
compile pynacl and pip install pynacl will now succeed.
Note it is optional to use the --virtual flag but it makes it easy to
trim the image because you can run apk del .pynacl_deps later in your
dockerfile as they are not needed any more and would reduce the
overall size of the image.

Categories