在Windows上为django构建docker映像时出现gcc错误

时间:2019-02-01 15:38:17

标签: django windows docker visual-studio-code pyodbc

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

我用pyodbc软件包创建了一个与azure上的MSSQLserver连接的django应用程序。

在构建docker映像期间,我收到以下错误消息:

        comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
        comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
        comboBox1.Items.AddRange(new []{"Omg", "So Kewel"," I love it"}); 

        comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
        comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;

        var list = new List<string>() {"Omg", "So Kewl", "I love it"};
        var collection = new AutoCompleteStringCollection();
        collection.AddRange(list.ToArray());

        comboBox1.AutoCompleteCustomSource = collection;

我阅读了应该安装python-dev的linux系统的解决方案,但是由于我在Windows机器上工作,所以这不是解决方案。

然后我读到在Windows上,所有需要的文件都在python安装的'include'目录中。但是在venv安装中,该目录为空...所以我创建了与原始“ include”的目录连接。该错误仍然存​​在。

我的docker文件包含在下面。

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

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

我可以在构建图像时使用一些帮助,而不会出现错误。


基于2ps的答案,我将这些行几乎添加到了docker文件的顶部

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

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

并收到新错误...

# 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"

发现添加

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

帮助解决了上述错误。摘自:https://github.com/gliderlabs/docker-alpine/issues/55


该应用程序现在可以正常工作,例如与MsSQL数据库的预期连接仍然不起作用。

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

我认为我应该认真阅读一些Docker文档。

2 个答案:

答案 0 :(得分:1)

我放弃了使用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

答案 1 :(得分:0)

您将需要使用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