gpt4 book ai didi

python - 在 docker 镜像中安装 pyodbc

转载 作者:太空宇宙 更新时间:2023-11-03 21:18:28 24 4
gpt4 key购买 nike

我正在使用https://hub.docker.com/r/tiangolo/meinheld-gunicorn-flask/托管 Flask api。

为了部署,我使用了一个 docker 镜像,该镜像托管在 Azure Web 应用服务上作为容器。我正在尝试将我的 Flask 应用程序连接到 Azure SQL 服务器。但我在安装正确的 odbc 驱动程序和 pyodbc 时遇到问题。

我的 docker 文件:

FROM ubuntu:16.04
# apt-get and system utilities
RUN apt-get update && apt-get install -y \
curl apt-utils apt-transport-https debconf-utils gcc build-essential g++-5\
&& rm -rf /var/lib/apt/lists/*
# adding custom MS repository
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

# install SQL Server drivers
RUN apt-get update && ACCEPT_EULA=Y apt-get -y install msodbcsql17
RUN apt-get -y install unixodbc unixodbc-dev

# install necessary locales
RUN apt-get update && apt-get install -y locales \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& locale-gen


FROM tiangolo/meinheld-gunicorn:python3.7
ENV LISTEN_PORT=80
EXPOSE 80

COPY /app /app

# Uncomment to install additional requirements from a requirements.txt file
COPY requirements.txt /


RUN pip install --no-cache-dir -U pip
RUN pip install --no-cache-dir -r /requirements.txt

收到错误:

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPYODBC_VERSION=4.0.25 -I/usr/local/include/python3.7m -c src/buffer.cpp -o build/temp.linux-x86_64-3.7/src/buffer.o -Wno-write-strings
2019-01-28T23:58:42.5006898Z In file included from src/buffer.cpp:12:0:
2019-01-28T23:58:42.5006979Z src/pyodbc.h:56:17: fatal error: sql.h: No such file or directory
2019-01-28T23:58:42.5007040Z #include <sql.h>
2019-01-28T23:58:42.5007105Z ^
2019-01-28T23:58:42.5007155Z compilation terminated.
2019-01-28T23:58:42.5007377Z error: command 'gcc' failed with exit status 1

我认为是因为 unixodbc 没有正确安装?

最佳答案

第二个 FROM 行可能意味着后续操作是使用不具有编译 pyodbc 所需的库的镜像执行的。

FROM tiangolo/meinheld-gunicorn:python3.7
ENV LISTEN_PORT=80
EXPOSE 80

欲了解更多信息,https://blog.alexellis.io/mutli-stage-docker-builds/

关于python - 在 docker 镜像中安装 pyodbc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54505370/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com