这是我第一次尝试使用pyodbc连接到docker映像中的Azure SQL数据库。我的Dockerfile如下所示:
# the base image
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
COPY music_trends.py ./
# install SQL Server drivers
RUN apt-get update
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql unixodbc-dev
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./music_trends.py" ]
哪个抛出错误消息:
E: Unable to locate package msodbcsql
The command '/bin/sh -c apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql unixodbc-dev' returned a non-zero code: 100
我找到了ubuntu:16.04的解析度,例如:https://github.com/Azure/azure-functions-docker/pull/45,并且还尝试从Dockerfile运行msodbcsql.msi文件。
是否存在python:3的等效修复程序?
答案 0 :(得分:1)
python:3
基于debian,因此请参考microsoft doc:
您应该安装Microsoft apt源,同时将msodbcsql
更改为msodbcsql17
,如下所示:
Dockerfile:
FROM python:3
RUN 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 unixodbc-dev -y
更新2019-07-26:
我没有注意到本月初从python:3
到debian 9
的官方debian 10
图片更新,请参阅this
从上面的Microsoft指南看来,当前他们只是将所有依赖项打包为下一个:
#Debian 8
curl https://packages.microsoft.com/config/debian/8/prod.list> /etc/apt/sources.list.d/mssql-release.list#Debian 9
curl https://packages.microsoft.com/config/debian/9/prod.list> /etc/apt/sources.list.d/mssql-release.list
当然,您可以自己处理debian 10依赖性,例如libcrypto.so
版本问题等,但是我仍然建议您使用python3 debian 9 version
,因为microsoft为您做了所有工作( PS:< / strong>我认为它们会在不久的将来更新,因为半个月前发布了debian 10,我想他们需要一些时间。顺便说一句,https://packages.microsoft.com/config/debian/10/prod.list
在那里,但目前没有软件包msodbcsql17 ...)
因此,与旧的Dockerfile
相比,我建议的最简单的方法是将python:3
更改为python:3-stretch
,然后安装apt-transport-https
,默认情况下未安装在debian 9
中,详细信息如下:
Dockerfile:
FROM python:3-stretch
RUN apt-get update && \
apt-get install -y 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 unixodbc-dev -y
。请检查:
root@91addb538736:/# ldd /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.3.so.1.1
linux-vdso.so.1 (0x00007ffd72bd0000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4892696000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f489248e000)
libodbcinst.so.2 => /usr/lib/x86_64-linux-gnu/libodbcinst.so.2 (0x00007f4892273000)
libcrypto.so.1.0.2 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2 (0x00007f4891e0d000)
libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f4891b33000)
libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f48918e8000)
libssl.so.1.0.2 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.2 (0x00007f489167f000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f489147a000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f48910f8000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4890df4000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4890bdd000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f48909c0000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4890621000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4892ca1000)
libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f48903ee000)
libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f48901ea000)
libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f488ffde000)
libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f488fdda000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f488fbc3000)