无法在Docker上构建简单的Django应用(必须具有Postgres + Mysql支持)

问题描述 投票:0回答:1

Dockerfile:

# pull official base image
FROM alpine:edge

RUN apk update && apk add build-base libzmq musl-dev python3 python3-dev zeromq-dev \
                  mariadb-dev postgresql-dev

RUN pip3 install pyzmq

# set work directory
WORKDIR /usr/src/myproj
COPY ./requirements.txt ./requirements.txt
# install dependencies
RUN pip3 install --upgrade pip
RUN pip3 install -r requirements.txt

COPY . /usr/src/myproj


# reduce image size by cleaning up the build packages
RUN apk del build-base musl-dev python3-dev zeromq-dev


EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

我的要求.txt

alive-progress==1.3.0
amqp==2.5.1
appnope==0.1.0
APScheduler==3.5.3
argh==0.26.2
astroid==2.2.4
attrs==19.1.0
awsebcli==3.14.4
Babel==2.6.0
backcall==0.1.0
billiard==3.6.1.0
bleach==3.1.0
blessed==1.15.0
botocore==1.10.84
bugsnag==3.6.0
cached-property==1.4.3
celery==4.3.0
cement==2.8.2
certifi==2018.8.24
chardet==3.0.4
colorama==0.3.9
decorator==4.3.2
defusedxml==0.5.0
dj-database-url==0.5.0
Django==2.2.4
django-cors-headers==3.0.2
django-enum-choices==2.1.1
django-enumchoicefield==2.0.0
django-extensions==2.2.1
django-redis==4.10.0
djangorestframework==3.9.4
dnspython==1.16.0
docker==3.5.0
docker-compose==1.21.2
docker-pycreds==0.3.0
dockerpty==0.4.1
docopt==0.6.2
docutils==0.14
entrypoints==0.3
flower==0.9.2
gunicorn==19.9.0
html2text==2019.9.26
idna==2.6
importlib-metadata==0.19
importlib-resources==1.0.2
ipykernel==5.1.0
ipython==7.3.0
ipython-genutils==0.2.0
ipywidgets==7.4.2
isodate==0.6.0
isort==4.3.10
jedi==0.13.3
Jinja2==2.10
jmespath==0.9.3
jsonfield==2.0.2
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.2.4
jupyter-console==6.0.0
jupyter-core==4.4.0
jwplatform==1.2.2
kombu==4.6.4
lazy-object-proxy==1.3.1
MarkupSafe==1.1.1
mccabe==0.6.1
mistune==0.8.4
more-itertools==7.2.0
mysql-connector==2.2.9
mysqlclient==1.4.6
nbconvert==5.4.1
nbformat==4.4.0
notebook==5.7.5
numpy==1.17.4
pandocfilters==1.4.2
parso==0.3.4
pathspec==0.5.5
pathtools==0.1.2
pexpect==4.6.0
pi==0.1.2
pickleshare==0.7.5
powerline-status==2.7
prometheus-client==0.6.0
prompt-toolkit==2.0.9
protobuf==3.6.1
psycopg2==2.7.5
psycopg2-binary==2.7.5
ptyprocess==0.6.0
Pygments==2.3.1
pylint==2.3.1
PyMySQL==0.9.3
pyrsistent==0.14.11
python-dateutil==2.7.3
python-slugify==3.0.3
pytz==2018.5
PyYAML==3.13
pyzmq==18.0.1
qtconsole==4.4.3
redis==3.3.8
requests==2.18.4
requests-toolbelt==0.9.1
semantic-version==2.5.0
Send2Trash==1.5.0
six==1.11.0
sqlparse==0.3.0
tabulate==0.7.5
termcolor==1.1.0
terminado==0.8.1
testpath==0.4.2
text-unidecode==1.2
texttable==0.9.1
timezonefinder==4.1.0
tornado==5.1
traitlets==4.3.2
typed-ast==1.3.1
tzlocal==1.5.1
Unidecode==1.1.1
urllib3==1.22
uWSGI==2.0.17.1
validators==0.14.0
vine==1.3.0
watchdog==0.9.0
wcwidth==0.1.7
webencodings==0.5.1
WebOb==1.8.5
websocket-client==0.51.0
widgetsnbextension==3.4.2
wrapt==1.11.1
zerobouncesdk==0.0.6
zipp==0.6.0

正在运行docker build会产生此错误:

ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-67emofjc/typed-ast/setup.py'"'"'; __file__='"'"'/tmp/pip-install-67emofjc/typed-ast/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-3om7rooa/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python3.8/typed-ast
         cwd: /tmp/pip-install-67emofjc/typed-ast/
    Complete output (23 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.8
    creating build/lib.linux-x86_64-3.8/typed_ast
    copying typed_ast/__init__.py -> build/lib.linux-x86_64-3.8/typed_ast
    copying typed_ast/conversions.py -> build/lib.linux-x86_64-3.8/typed_ast
    copying typed_ast/ast27.py -> build/lib.linux-x86_64-3.8/typed_ast
    copying typed_ast/ast3.py -> build/lib.linux-x86_64-3.8/typed_ast
    running build_ext
    building '_ast27' extension
    creating build/temp.linux-x86_64-3.8
    creating build/temp.linux-x86_64-3.8/ast27
    creating build/temp.linux-x86_64-3.8/ast27/Parser
    creating build/temp.linux-x86_64-3.8/ast27/Python
    creating build/temp.linux-x86_64-3.8/ast27/Custom
    gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -DTHREAD_STACK_SIZE=0x100000 -fPIC -Iast27/Include -I/usr/include/python3.8 -c ast27/Parser/acceler.c -o build/temp.linux-x86_64-3.8/ast27/Parser/acceler.o
    ast27/Parser/acceler.c:13:10: fatal error: pgenheaders.h: No such file or directory
       13 | #include "pgenheaders.h"
          |          ^~~~~~~~~~~~~~~
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-67emofjc/typed-ast/setup.py'"'"'; __file__='"'"'/tmp/pip-install-67emofjc/typed-ast/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-3om7rooa/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python3.8/typed-ast Check the logs for full command output.
django docker dockerfile alpine
1个回答
0
投票
根据我的上述评论,似乎typed-ast==1.3.1并未安装在python 3.8下(这是运行alpine:edge时安装在apk add python3中的版本)。

[确认我已经对基于高山的python官方图像进行了以下测试:

    docker run -it --rm --name test python:3.6-alpine sh -c "apk add build-base && pip install typed-ast==1.3.1" =>确定
  • docker run -it --rm --name test python:3.7-alpine sh -c "apk add build-base && pip install typed-ast==1.3.1" =>确定
  • docker run -it --rm --name test python:3.8-alpine sh -c "apk add build-base && pip install typed-ast==1.3.1" =>
  • KO
[我建议您尝试从兼容的官方python映像(即<3.8)开始构建上述应用程序
© www.soinside.com 2019 - 2024. All rights reserved.