0

I am trying to deploy a Flask Rest API on RHEL 7.3 LINUX machine using docker and got following error after building the Docker image and trying to run it.

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?'

Below is my Docker file. Am I missing something?

#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"]
SSingh
  • 199
  • 2
  • 11
  • Did you read this [post](https://stackoverflow.com/questions/44825966/trying-to-import-pypyodbc-module-gives-error-odbc-library-is-not-found-is-ld-l)? You seem to have to `sudo apt-get install unixodbc` – hyun Apr 04 '18 at 01:47

1 Answers1

0

This is what worked for me.

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"]
SSingh
  • 199
  • 2
  • 11