首页 > 解决方案 > 无法在 Python Flask 应用程序中构建 Docker 容器映像

问题描述

为了确保我们的烧瓶应用程序具有 GDAL 并存储来自某个特定位置的数据,我们使用 docker 来确保最终产品上存在所有依赖项。问题是我似乎无法在我身边建立 docker 容器映像。虽然它肯定适用于我的队友方面它会拒绝在我方面工作,但请注意我已经对我的程序名称进行了分类。那么任何人都可以帮助我吗?

D:\Programmeer portfolio\Flask\Classified>docker-compose build --force-rm
Building Classified
[+] Building 19.2s (11/12)
 => [internal] load build definition from Dockerfile                                                               0.2s
 => => transferring dockerfile: 1.31kB                                                                             0.0s
 => [internal] load .dockerignore                                                                                  0.1s
 => => transferring context: 35B                                                                                   0.0s
 => [internal] load metadata for docker.io/library/python:3.8-slim-buster                                          2.1s
 => [internal] load build context                                                                                  0.1s
 => => transferring context: 51B                                                                                   0.0s
 => [1/8] FROM docker.io/library/python:3.8-slim-buster@sha256:e9087bce99087a2eca8cb5cc8278de16d7907aee25c47b33bd  0.0s
 => CACHED [2/8] WORKDIR /Classified                                                                               0.0s
 => CACHED [3/8] COPY requirements-pythonenvwin.txt requirements.txt                                               0.0s
 => CACHED [4/8] RUN apt-get -y update                                                                             0.0s
 => CACHED [5/8] RUN apt-get -y install iputils-ping                                                               0.0s
 => CACHED [6/8] RUN apt-get -y install gis-all                                                                    0.0s
 => ERROR [7/8] RUN apt-get -y update &&     apt-get -y install python3-pip gdal-bin python3-gdal &&  pip3 insta  16.7s
------
 > [7/8] RUN apt-get -y update &&     apt-get -y install python3-pip gdal-bin python3-gdal &&   pip3 install -r requirements.txt:
#11 1.035 Hit:1 http://deb.debian.org/debian buster InRelease
#11 1.035 Hit:2 http://security.debian.org/debian-security buster/updates InRelease
#11 1.150 Hit:3 http://deb.debian.org/debian buster-updates InRelease
#11 1.713 Reading package lists...
#11 3.005 Reading package lists...
#11 4.247 Building dependency tree...
#11 4.499 Reading state information...
#11 4.819 gdal-bin is already the newest version (2.4.0+dfsg-1+b1).
#11 4.819 gdal-bin set to manually installed.
#11 4.819 The following additional packages will be installed:
#11 4.819   build-essential dh-python dirmngr dpkg-dev fakeroot gnupg gnupg-l10n
#11 4.819   gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf gpgsm
#11 4.819   libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl
#11 4.820   libassuan0 libfakeroot libksba8 libnpth0 libpython3-dev libpython3.7
#11 4.821   libpython3.7-dev make patch pinentry-curses python-pip-whl
#11 4.821   python3-asn1crypto python3-cffi-backend python3-crypto python3-cryptography
#11 4.821   python3-dbus python3-dev python3-distutils python3-entrypoints python3-gi
#11 4.822   python3-keyring python3-keyrings.alt python3-lib2to3 python3-secretstorage
#11 4.824   python3-setuptools python3-wheel python3-xdg python3.7-dev
#11 4.827 Suggested packages:
#11 4.827   pinentry-gnome3 tor debian-keyring parcimonie xloadimage scdaemon make-doc
#11 4.827   ed diffutils-doc pinentry-doc python-crypto-doc python-cryptography-doc
#11 4.827   python3-cryptography-vectors python-dbus-doc python3-dbus-dbg gnome-keyring
#11 4.827   libkf5wallet-bin gir1.2-gnomekeyring-1.0 python-secretstorage-doc
#11 4.827   python-setuptools-doc
#11 5.418 The following NEW packages will be installed:
#11 5.420   build-essential dh-python dirmngr dpkg-dev fakeroot gnupg gnupg-l10n
#11 5.420   gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf gpgsm
#11 5.420   libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl
#11 5.423   libassuan0 libfakeroot libksba8 libnpth0 libpython3-dev libpython3.7
#11 5.425   libpython3.7-dev make patch pinentry-curses python-pip-whl
#11 5.425   python3-asn1crypto python3-cffi-backend python3-crypto python3-cryptography
#11 5.425   python3-dbus python3-dev python3-distutils python3-entrypoints python3-gdal
#11 5.425   python3-gi python3-keyring python3-keyrings.alt python3-lib2to3 python3-pip
#11 5.425   python3-secretstorage python3-setuptools python3-wheel python3-xdg
#11 5.427   python3.7-dev
#11 5.691 0 upgraded, 47 newly installed, 0 to remove and 0 not upgraded.
#11 5.691 Need to get 64.0 MB of archives.
#11 5.691 After this operation, 122 MB of additional disk space will be used.
#11 5.691 Get:1 http://deb.debian.org/debian buster/main amd64 make amd64 4.2.1-1.2 [341 kB]
#11 5.916 Get:2 http://deb.debian.org/debian buster/main amd64 patch amd64 2.7.6-3+deb10u1 [126 kB]
#11 6.037 Get:3 http://deb.debian.org/debian buster/main amd64 dpkg-dev all 1.19.7 [1773 kB]
#11 6.402 Get:4 http://deb.debian.org/debian buster/main amd64 build-essential amd64 12.6 [7576 B]
#11 6.551 Get:5 http://deb.debian.org/debian buster/main amd64 python3-lib2to3 all 3.7.3-1 [76.7 kB]
#11 6.614 Get:6 http://deb.debian.org/debian buster/main amd64 python3-distutils all 3.7.3-1 [142 kB]
#11 6.671 Get:7 http://deb.debian.org/debian buster/main amd64 dh-python all 3.20190308 [99.3 kB]
#11 6.750 Get:8 http://deb.debian.org/debian buster/main amd64 libassuan0 amd64 2.5.2-1 [49.4 kB]
#11 6.806 Get:9 http://deb.debian.org/debian buster/main amd64 gpgconf amd64 2.2.12-1+deb10u1 [510 kB]
#11 6.896 Get:10 http://deb.debian.org/debian buster/main amd64 libksba8 amd64 1.3.5-2 [99.7 kB]
#11 6.930 Get:11 http://deb.debian.org/debian buster/main amd64 libnpth0 amd64 1.6-1 [18.4 kB]
#11 6.949 Get:12 http://deb.debian.org/debian buster/main amd64 dirmngr amd64 2.2.12-1+deb10u1 [712 kB]
#11 7.056 Get:13 http://deb.debian.org/debian buster/main amd64 libfakeroot amd64 1.23-1 [45.9 kB]
#11 7.093 Get:14 http://deb.debian.org/debian buster/main amd64 fakeroot amd64 1.23-1 [85.8 kB]
#11 7.103 Get:15 http://deb.debian.org/debian buster/main amd64 gnupg-l10n all 2.2.12-1+deb10u1 [1010 kB]
#11 7.280 Get:16 http://deb.debian.org/debian buster/main amd64 gnupg-utils amd64 2.2.12-1+deb10u1 [861 kB]
#11 7.395 Get:17 http://deb.debian.org/debian buster/main amd64 gpg amd64 2.2.12-1+deb10u1 [865 kB]
#11 7.700 Get:18 http://deb.debian.org/debian buster/main amd64 pinentry-curses amd64 1.1.0-2 [64.5 kB]
#11 7.704 Get:19 http://deb.debian.org/debian buster/main amd64 gpg-agent amd64 2.2.12-1+deb10u1 [617 kB]
#11 7.796 Get:20 http://deb.debian.org/debian buster/main amd64 gpg-wks-client amd64 2.2.12-1+deb10u1 [485 kB]
#11 7.857 Get:21 http://deb.debian.org/debian buster/main amd64 gpg-wks-server amd64 2.2.12-1+deb10u1 [478 kB]
#11 7.963 Get:22 http://deb.debian.org/debian buster/main amd64 gpgsm amd64 2.2.12-1+deb10u1 [604 kB]
#11 8.042 Get:23 http://deb.debian.org/debian buster/main amd64 gnupg all 2.2.12-1+deb10u1 [715 kB]
#11 8.159 Get:24 http://deb.debian.org/debian buster/main amd64 libalgorithm-diff-perl all 1.19.03-2 [47.9 kB]
#11 8.161 Get:25 http://deb.debian.org/debian buster/main amd64 libalgorithm-diff-xs-perl amd64 0.04-5+b1 [11.8 kB]
#11 8.163 Get:26 http://deb.debian.org/debian buster/main amd64 libalgorithm-merge-perl all 0.08-3 [12.7 kB]
#11 8.163 Get:27 http://deb.debian.org/debian buster/main amd64 libpython3.7 amd64 3.7.3-2+deb10u3 [1498 kB]
#11 8.389 Get:28 http://deb.debian.org/debian buster/main amd64 libpython3.7-dev amd64 3.7.3-2+deb10u3 [48.4 MB]
#11 14.40 Err:29 http://deb.debian.org/debian buster/main amd64 libpython3-dev amd64 3.7.3-1
#11 14.40   Bad header line Bad header data [IP: 199.232.150.132 80]
#11 14.53 Get:30 http://deb.debian.org/debian buster/main amd64 python-pip-whl all 18.1-5 [1591 kB]
#11 14.85 Get:31 http://deb.debian.org/debian buster/main amd64 python3-asn1crypto all 0.24.0-1 [78.2 kB]
#11 14.86 Get:32 http://deb.debian.org/debian buster/main amd64 python3-cffi-backend amd64 1.12.2-1 [79.7 kB]
#11 14.86 Get:33 http://deb.debian.org/debian buster/main amd64 python3-crypto amd64 2.6.1-9+b1 [263 kB]
#11 14.91 Get:34 http://deb.debian.org/debian buster/main amd64 python3-cryptography amd64 2.6.1-3+deb10u2 [219 kB]
#11 14.95 Get:35 http://deb.debian.org/debian buster/main amd64 python3-dbus amd64 1.2.8-3 [103 kB]
#11 14.99 Get:36 http://deb.debian.org/debian buster/main amd64 python3.7-dev amd64 3.7.3-2+deb10u3 [510 kB]
#11 15.06 Get:37 http://deb.debian.org/debian buster/main amd64 python3-dev amd64 3.7.3-1 [1264 B]
#11 15.09 Get:38 http://deb.debian.org/debian buster/main amd64 python3-entrypoints all 0.3-1 [5508 B]
#11 15.13 Get:39 http://deb.debian.org/debian buster/main amd64 python3-gdal amd64 2.4.0+dfsg-1+b1 [601 kB]
#11 15.22 Get:40 http://deb.debian.org/debian buster/main amd64 python3-gi amd64 3.30.4-1 [180 kB]
#11 15.25 Get:41 http://deb.debian.org/debian buster/main amd64 python3-secretstorage all 2.3.1-2 [14.2 kB]
#11 15.29 Get:42 http://deb.debian.org/debian buster/main amd64 python3-keyring all 17.1.1-1 [43.1 kB]
#11 15.34 Get:43 http://deb.debian.org/debian buster/main amd64 python3-keyrings.alt all 3.1.1-1 [18.2 kB]
#11 15.39 Get:44 http://deb.debian.org/debian buster/main amd64 python3-pip all 18.1-5 [171 kB]
#11 15.46 Get:45 http://deb.debian.org/debian buster/main amd64 python3-setuptools all 40.8.0-1 [306 kB]
#11 15.53 Get:46 http://deb.debian.org/debian buster/main amd64 python3-wheel all 0.32.3-2 [19.4 kB]
#11 15.56 Get:47 http://deb.debian.org/debian buster/main amd64 python3-xdg all 0.25-5 [35.9 kB]
#11 15.58 E: Failed to fetch http://deb.debian.org/debian/pool/main/p/python3-defaults/libpython3-dev_3.7.3-1_amd64.deb  Bad header line Bad header data [IP: 199.232.150.132 80]
#11 15.58 E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
#11 15.58 Fetched 64.0 MB in 10s (6338 kB/s)
------
executor failed running [/bin/sh -c apt-get -y update &&     apt-get -y install python3-pip gdal-bin python3-gdal &&   pip3 install -r requirements.txt]: exit code: 100
ERROR: Service 'Classified failed to build : Build failed

这是码头文件:

FROM python:3.8-slim-buster

ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV FLASK_ENV=development
ENV FLASK_APP=FlaskWebPODTracer
ENV FLASK_RUN_PORT=5555
ENV SERVER_HOST=0.0.0.0
ENV SERVER_PORT=5555
ENV DATA_DIR='/data'

# Set up container workdir and copy all files project root
WORKDIR /app
COPY requirements-pythonenvwin.txt requirements.txt

RUN apt-get -y update
# IP utils for basic troubleshooting
RUN apt-get -y install iputils-ping
RUN apt-get -y install gis-all

RUN apt-get -y update && \
    apt-get -y install python3-pip gdal-bin python3-gdal && \
    pip3 install -r requirements.txt

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser

EXPOSE 5555:5555

# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
# CMD ["gunicorn", "--bind", "0.0.0.0:5555", "runserver:app"]
# CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
CMD ["python3", "runserver.py"]

version: '2'

services:
  podtracer:
    build: .
    container_name: Classified
    expose:
      - "5555"
    ports:
      - "5555:5555"
    # Set network to bridge mode. This will make sure we have internet access for the GIPOD API
    network_mode: bridge
    # Volumes. This will mount the _data folder as /data/ in the container
    volumes:
      - ./_data:/data
    image: Classified/Clasified

volumes:
  data:

这里也是 Requirement.txt 文件:

amqp==5.0.6
billiard==3.6.4.0
blinker==1.4
celery==5.0.5
celerycontrib.sqlalchemyscheduler==0.1.1.dev0
certifi==2020.12.5
cffi==1.14.5
chardet==4.0.0
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.1.6
cryptography==3.4.7
DateTime==4.3
decorator==5.0.7
Deprecated==1.2.12
Flask==1.1.2
Flask-Celery-Helper==1.1.0
Flask-Mail==0.9.1
GDAL==3.2.2
gitdb==4.0.7
GitPython==3.1.14
greenlet==1.0.0
idna==2.10
importlib-metadata==4.0.1
install==1.3.4
itsdangerous==1.1.0
Jinja2==2.11.3
kombu==5.0.2
MarkupSafe==1.1.1
numpy==1.20.2
ogr==0.23.0
osgeo4w-installer==1.4.0
pandas==1.2.4
pip==21.1
pretty-cron==1.2.0
prompt-toolkit==3.0.18
py==1.10.0
pycparser==2.20
PyGithub==1.54.1
PyJWT==1.7.1
python-dateutil==2.8.1
python-gitlab==2.6.0
pytz==2021.1
PyYAML==5.4.1
requests==2.25.1
requests-toolbelt==0.9.1
retry==0.9.2
setuptools==47.1.0
six==1.15.0
smmap==4.0.0
SQLAlchemy==1.4.11
tqdm==4.60.0
typing-extensions==3.7.4.3
urllib3==1.26.4
vine==5.0.0
wcwidth==0.2.5
Werkzeug==1.0.1
wheel==0.36.2
wrapt==1.12.1
zipp==3.4.1
zope.interface==5.4.0

标签: pythondocker

解决方案


推荐阅读