3

I'm trying to build a Docker container for my Python web application that uses Flask and PostgreSQL.I work with Windows 10 and use Python 3.7.3, PostgreSQL 13 and PyCharm. Here is my Dockerfile:

FROM python:3.7

WORKDIR /app

COPY requirements.txt ./
RUN pip install --trusted-host pypi.python.org -r requirements.txt

RUN export PYTHONPATH='${PYTHONPATH}:/app'

COPY . .

CMD ["python", "./run.py"]

And requierements.txt file:

click==7.1.2
Flask==1.1.2
Flask-SQLAlchemy==2.4.4
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
psycopg2==2.8.6
SQLAlchemy==1.3.20
Werkzeug==1.0.1

All files look normal, but when I try to build a container, I get an error:

D:\PyCharms\Module 6\app>docker build -t doc .
[+] Building 91.6s (8/10)
 => [internal] load build definition from Dockerfile                                                                                                                                                             3.6s
 => => transferring dockerfile: 256B                                                                                                                                                                             1.6s
 => [internal] load .dockerignore                                                                                                                                                                                1.4s
 => => transferring context: 2B                                                                                                                                                                                  0.1s
 => [internal] load metadata for docker.io/library/python:3.7                                                                                                                                                    9.4s
 => [1/6] FROM docker.io/library/python:3.7@sha256:bdd950df83006ce9e7f7f9cb878a2ca72e945f3cbd37faef07509c8510d22ba8                                                                                              0.3s
 => [internal] load build context                                                                                                                                                                                7.1s
 => => transferring context: 172.02kB                                                                                                                                                                            5.2s
 => CACHED [2/6] WORKDIR /app                                                                                                                                                                                    0.0s
 => CACHED [3/6] COPY requirements.txt ./                                                                                                                                                                        0.0s
 => ERROR [4/6] RUN pip install --trusted-host pypi.python.org -r requirements.txt                                                                                                                              70.7s
------
 > [4/6] RUN pip install --trusted-host pypi.python.org -r requirements.txt:
#8 55.94 Collecting click==7.1.2
#8 56.54   Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
#8 56.90 Collecting Flask==1.1.2
#8 57.01   Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
#8 57.74 Collecting Flask-SQLAlchemy==2.4.4
#8 57.89   Downloading Flask_SQLAlchemy-2.4.4-py2.py3-none-any.whl (17 kB)
#8 58.55 Collecting itsdangerous==1.1.0
#8 58.66   Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)
#8 58.96 Collecting Jinja2==2.11.2
#8 59.07   Downloading Jinja2-2.11.2-py2.py3-none-any.whl (125 kB)
#8 59.55 Collecting MarkupSafe==1.1.1
#8 59.65   Downloading MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl (27 kB)
#8 59.88 Collecting psycopg2==2.8.6
#8 60.00   Downloading psycopg2-2.8.6.tar.gz (383 kB)
#8 64.98     ERROR: Command errored out with exit status 1:
#8 64.98      command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-0g810mp0/psycopg2_ac2d50477f704274a8d0a974f85ef1b7/setup.py'"'"'; __file__='"'"'/tmp/pip-install-0g810mp0/psycopg2_ac2d50477f704274a8d0a974f85ef1b7/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-8yce09_u
#8 64.98          cwd: /tmp/pip-install-0g810mp0/psycopg2_ac2d50477f704274a8d0a974f85ef1b7/
#8 64.98     Complete output (7 lines):
#8 64.98     running egg_info
#8 64.98     creating /tmp/pip-pip-egg-info-8yce09_u/psycopg2.egg-info
#8 64.98     writing /tmp/pip-pip-egg-info-8yce09_u/psycopg2.egg-info/PKG-INFO
#8 64.98     writing dependency_links to /tmp/pip-pip-egg-info-8yce09_u/psycopg2.egg-info/dependency_links.txt
#8 64.98     writing top-level names to /tmp/pip-pip-egg-info-8yce09_u/psycopg2.egg-info/top_level.txt
#8 64.98     writing manifest file '/tmp/pip-pip-egg-info-8yce09_u/psycopg2.egg-info/SOURCES.txt'
#8 64.98     Error: b'strict.pm did not return a true value at /usr/bin/pg_config line 12.\n'
#8 64.98     ----------------------------------------
#8 64.99 ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
------
executor failed running [/bin/sh -c pip install --trusted-host pypi.python.org -r requirements.txt]: exit code: 1

Looks like there is some problem with installing psycopg(concretely, some trouble with pg_config file), but I didn't find any useful information about that kind of error. Only one tip I found is that "strict.pm" is some kind of Perl file, that should end with "1;" line or something like that. So my questions are:

  1. What is "strict.pm" file and what is connection between it and pg_config and psycopg?
  2. How I can get rid of this kind of error?

(P.S. I'm complete newbie in Docker and Postgre stuff and this is my first question, so sorry for possible mistakes)

  • It's not quite exactly the same error, but have you looked at [Error: pg_config executable not found when installing psycopg2 on Alpine in Docker](https://stackoverflow.com/questions/46711990/error-pg-config-executable-not-found-when-installing-psycopg2-on-alpine-in-dock)? – David Maze Dec 27 '20 at 18:35
  • Your docker file worked fine on my machine. I wonder if you have an old base image. Perhaps you could try pulling python:3.7 again? Otherwise you could share the base image hash, which would help us reproduce. e.g. ```docker image inspect --format "{{.ID}}" python:3.7``` – Frank Wilson Dec 27 '20 at 20:26
  • @DavidMaze, thanks for the link, it worked =) Problem solved. – Horokhov Vasyl Dec 28 '20 at 20:09

0 Answers0