簡體   English   中英

在 Windows 上為 django 構建 docker 映像時出現 gcc 錯誤

[英]gcc error while building docker image for django on windows

我正在嘗試按照本教程“ https://code.visualstudio.com/docs/python/tutorial-deploy-containers ”使用 Visual Studio Code 構建 docker 映像。

我使用 pyodbc 包創建了一個 django 應用程序,該應用程序連接到 azure 上的 MSSQLserver。

在構建 docker 映像期間,我收到以下錯誤消息:

unable to execute 'gcc': No such file or directory   
error: command 'gcc' failed with exit status 1

----------------------------------------   
 Failed building wheel for pyodbc

  unable to execute 'gcc': No such file or directory
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for typed-ast

我閱讀了應該安裝 python-dev 的 linux 系統的解決方案,但由於我在 Windows 機器上工作,這不是解決方案。

然后我讀到在 Windows 上所有需要的文件都在 python 安裝的“包含”目錄中。 但是在 venv 安裝中,這個目錄是空的……所以我創建了一個到原始“include”的目錄連接。 錯誤仍然存​​在。

我的 docker 文件包含在下面。

# Python support can be specified down to the minor or micro version
# (e.g. 3.6 or 3.6.3).
# OS Support also exists for jessie & stretch (slim and full).
# See https://hub.docker.com/r/library/python/ for all supported Python
# tags from Docker Hub.
FROM tiangolo/uwsgi-nginx:python3.6-alpine3.7

# Indicate where uwsgi.ini lives
ENV UWSGI_INI uwsgi.ini

# Tell nginx where static files live (as typically collected using Django's
# collectstatic command.
ENV STATIC_URL /app/static_collected

# Copy the app files to a folder and run it from there
WORKDIR /app
ADD . /app

# Make app folder writable for the sake of db.sqlite3, and make that file also writable.
# RUN chmod g+w /app
# RUN chmod g+w /app/db.sqlite3

# If you prefer miniconda:
#FROM continuumio/miniconda3

LABEL Name=hello_django Version=0.0.1
EXPOSE 8000

# Using pip:
RUN python3 -m pip install -r requirements.txt
CMD ["python3", "-m", "hello_django"]

# Using pipenv:
#RUN python3 -m pip install pipenv
#RUN pipenv install --ignore-pipfile
#CMD ["pipenv", "run", "python3", "-m", "hello_django"]

# Using miniconda (make sure to replace 'myenv' w/ your environment name):
#RUN conda env create -f environment.yml
#CMD /bin/bash -c "source activate myenv && python3 -m hello_django"

我可以使用一些幫助來構建沒有錯誤的圖像。


根據 2ps 的回答,我幾乎在 docker 文件的頂部添加了這些行

FROM tiangolo/uwsgi-nginx:python3.6-alpine3.7

RUN apk update \
  && apk add apk add gcc libc-dev g++ \
  && apk add libffi-dev libxml2 libffi-dev \
  && apk add unixodbc-dev mariadb-dev python3-dev

並收到一個新的錯誤...

fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
v3.7.1-98-g2f2e944c59 [http://dl-cdn.alpinelinux.org/alpine/v3.7/main]
v3.7.1-105-g7db92f4321 [http://dl-cdn.alpinelinux.org/alpine/v3.7/community]
OK: 9053 distinct packages available
ERROR: unsatisfiable constraints:
  add (missing):
    required by: world[add]
  apk (missing):
    required by: world[apk]
The command '/bin/sh -c apk update   && apk add apk add gcc libc-dev g++   && apk add libffi-dev libxml2 libffi-dev   && apk add unixodbc-dev mariadb-dev python3-dev' returned a non-zero code: 2

發現添加

RUN echo "ipv6" >> /etc/modules

幫助解決了上述錯誤。 摘自: https : //github.com/gliderlabs/docker-alpine/issues/55


該應用程序現在可以工作,但與 MsSQL 數據庫的預期連接仍然無法正常工作。

Error at /

('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (0) (SQLDriverConnect)")

我想我應該了解一些 docker 文檔。

您需要使用apk來安裝gcc和構建pip依賴項所需的其他本機依賴項。 對於您列出的那些(typedast 和 pyodbc),我認為它們是:

RUN apk update \
  && apk add apk add gcc libc-dev g++ \
  && apk add libffi-dev libxml2 libffi-dev \
  && apk add unixodbc-dev mariadb-dev python3-dev

我放棄了 alpine 的解決方案,轉而使用 debian

FROM python:3.7

# needed files for pyodbc
RUN apt-get update
RUN apt-get install gcc libc-dev g++ libffi-dev libxml2 libffi-dev unixodbc-dev -y

# MS SQL driver 17 for debian
RUN apt-get install apt-transport-https \
    && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -\
    && curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list \
    && apt-get update \
    && ACCEPT_EULA=Y apt-get install msodbcsql17 -y

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM