在Docker容器中连接到PyodBC的问题

发布于 2025-02-05 20:16:26 字数 680 浏览 1 评论 0原文

早上好,

我的docker容器和pyodbc / unixoDBC-dev遇到了以下问题。

运行我的Python API连接到我的Docker容器时,我会收到以下错误消息 -

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

使用本地调试实例连接到同一API,一切都很好 - 我可以在后端数据库中提交一个字符串,并返回结果并送回邮递员UI。

我看到docker映像中安装的UnixODBC-DEV DEV 2.3.6-0.1 AMD64,我注意到UnixoDBC为2.3.11-不知道是否有任何问题,但说我们的月经实例可以' t连接到 http://deb.debian.org ,要让我们的安全集团打开它,这是下一个不可能。

话虽这么说,我想知道我在码头容器中是否有任何配置的东西,这引起了我的问题。我是Docker容器世界的新手,所以这绝对是我走的学习。

蒂亚, 比尔·扬曼(Bill Youngman)

Good Morning,

I am having the following issue with my Docker container and pyodbc / unixodbc-dev.

When running my Python API connecting to my Docker container I get the following error message--

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

Connecting to the same API using my local debug instance everything is working fine -- I can submit a string for searching in the backend database and I get results returned and sent back to the Postman UI.

I see that unixodbc-dev dev 2.3.6-0.1 amd64 installed in the Docker image and I noticed that unixODBC is at 2.3.11 - don't know if there might be any issue with that but that being said our Moonshot instances can't connect to http://deb.debian.org and to get our security group to open it up is next to impossible.

All this being said I'm wondering if I have something configured wrong in my Docker container that is causing my issues. I'm new to the Docker container world so this is definitely a learn as I go.

TIA,
Bill Youngman

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

離殇 2025-02-12 20:16:27

我能够解决这个问题 - 感谢 mb 对于我正在寻找的解决方案。

我能够从此安装Alpine Linux中的Debian建议。 Docker容器并为我的需求进行修改。

这是我用来满足下载UnixODBC以及下载和安装MS SQL ODBC驱动程序的代码。

FROM python:3.8.3

ARG ENV DEBIAN_FRONTEND noninteractive

# install Microsoft SQL Server requirements.
ENV ACCEPT_EULA=Y
RUN apt-get update -y && apt-get update \
  && apt-get install -y --no-install-recommends curl gcc g++ gnupg unixodbc-dev

# Add SQL Server ODBC Driver 17 for Ubuntu 18.04
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
  && curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list \
  && apt-get update \
  && apt-get install -y --no-install-recommends --allow-unauthenticated msodbcsql17 mssql-tools \
  && echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile \
  && echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc

# clean the install.
RUN apt-get -y clean

完成此操作后,我建造并部署了我的容器,一切正常。

-账单

I was able to get this figured out - thanks to m.b. for the solution I was looking for.

I was able to take the Debian suggestion from this Install ODBC driver in Alpine Linux Docker Container and modify it for my needs.

This is the code that I used to meet my requirements of downloading unixOdbc as well as downloading and installing the MS Sql ODBC driver.

FROM python:3.8.3

ARG ENV DEBIAN_FRONTEND noninteractive

# install Microsoft SQL Server requirements.
ENV ACCEPT_EULA=Y
RUN apt-get update -y && apt-get update \
  && apt-get install -y --no-install-recommends curl gcc g++ gnupg unixodbc-dev

# Add SQL Server ODBC Driver 17 for Ubuntu 18.04
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
  && curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list \
  && apt-get update \
  && apt-get install -y --no-install-recommends --allow-unauthenticated msodbcsql17 mssql-tools \
  && echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile \
  && echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc

# clean the install.
RUN apt-get -y clean

Once this was accomplished and I built and deployed my container everything worked perfectly.

-Bill

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文