【问题标题】:Docker run error 'ODBC Library is not found. Is LD_LIBRARY_PATH set?')Docker 运行错误“找不到 ODBC 库。是否设置了 LD_LIBRARY_PATH?')
【发布时间】:2018-04-03 22:31:00
【问题描述】:

我正在尝试使用 docker 在 RHEL 7.3 LINUX 机器上部署 Flask Rest API,并在构建 Docker 映像并尝试运行它后出现以下错误。

Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/pypyodbc.py", line 428, in 
<module>
ODBC_API = ctypes.cdll.LoadLibrary('libodbc.so')
File "/usr/local/lib/python3.6/ctypes/__init__.py", line 426, in LoadLibrary
return self._dlltype(name)
File "/usr/local/lib/python3.6/ctypes/__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libodbc.so: cannot open shared object file: No such file or 
directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "app.py", line 5, in <module>
import utils as u
File "/PYTHDEV/parquetfiles/utils.py", line 11, in <module>
import pypyodbc as db
File "/usr/local/lib/python3.6/site-packages/pypyodbc.py", line 440, in 
<module>
raise OdbcNoLibrary('ODBC Library is not found. Is LD_LIBRARY_PATH set?')
 pypyodbc.OdbcNoLibrary: 'ODBC Library is not found. Is LD_LIBRARY_PATH 
set?'

下面是我的 Docker 文件。我错过了什么吗?

#Pull base image
FROM python:3.6

#Define working directory
WORKDIR /PYTHDEV/parquetfiles

#Build Commands
#RUN cd /PYTHDEV/
#RUN mkdir pq_flask_api
ADD requirements.txt /PYTHDEV/parquetfiles

RUN pip install -r /PYTHDEV/parquetfiles/requirements.txt
ADD . /PYTHDEV/parquetfiles

RUN PATH="/opt/mssql-tools/bin:/etc/:$PATH"
RUN LD_LIBRARY_PATH="/opt/mssql-tools/bin:/etc/:$PATH"

#Define default commands
EXPOSE 5000
CMD ["python3", "app.py"]

【问题讨论】:

  • 你读过这个post吗?你似乎必须sudo apt-get install unixodbc

标签: python docker flask odbc


【解决方案1】:

这对我有用。

FROM centos:latest

#Define working directory
WORKDIR /PYTHDEV/pq_flask_api

RUN yum groupinstall "Development Tools" -y
RUN yum -y install wget zlib-devel bzip2-devel openssl-devel ncurses-devel 
sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz- 
devel  unixODBC-devel
RUN wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
RUN tar xJf Python-3.6.4.tar.xz
RUN cd Python-3.6.4 && ./configure --enable-optimizations --enable-loadable- 
sqlite-extensions --prefix=/usr --enable-shared --enable-loadable-sqlite- 
extensions --with-system-expat --with-system-ffi --with-ensurepip=yes && 
make && make install
RUN chmod -v 755 /usr/lib/libpython3.6m.so
RUN chmod -v 755 /usr/lib/libpython3.so
RUN echo '/usr/local/lib' >> /etc/ld.so.conf
RUN ldconfig -v
RUN curl -k  https://packages.microsoft.com/config/rhel/7/prod.repo > 
/etc/yum.repos.d/mssql-release.repo
RUN yum remove unixODBC-utf16 unixODBC-utf16-devel
RUN ACCEPT_EULA=Y yum -y install msodbcsql17
RUN ACCEPT_EULA=Y yum -y install mssql-tools
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN source ~/.bashrc

ENV PATH="${PATH}"

ADD requirements.txt /PYTHDEV/pq_flask_api

RUN pip3 install --trusted-host files.pythonhosted.org -r 
/PYTHDEV/pq_flask_api/requirements.txt

RUN mkdir ./pqdatastore

ADD . /PYTHDEV/pq_flask_api

#Define default commands
EXPOSE 5000
CMD ["python", "app.py"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    • 2016-11-22
    • 2012-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多