ODBC Driver Error: File Not Found When Running Python Script in Docker Container

I'm running a Python script (sharepoint_to_json.py) inside a Docker container that connects to a SQL Server database using the ODBC driver. My goal is to convert data from an Excel (.xlsx) file into JSON format within my server, using the sharepoint_to_json.py script. This process should run inside the Docker container after establishing a connection to a SQL Server database.

I have already installed the msodbcsql17 driver in the container, and my connection to the database works when running other scripts. However, when I try to run the sharepoint_to_json.py script, I encounter the following error:

Ocorreu um erro ao processar o arquivo Excel: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.9.so.1.1' : file not found (0) (SQLDriverConnect)")

Here's the relevant part of my Dockerfile:

FROM python:3.12

RUN apt-get update && apt-get install -y
curl
gnupg2
apt-transport-https
unixodbc
unixodbc-dev
python3-distutils
build-essential
&& 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 && ACCEPT_EULA=Y apt-get install -y msodbcsql17

Set the working directory in the container

WORKDIR /app

Upgrade pip, setuptools, wheel to ensure the latest versions

RUN pip install --upgrade pip setuptools wheel

Copy the requirements.txt file

COPY requirements.txt .

Install the dependencies

RUN pip install -r requirements.txt

Copy the project files

COPY . /app/

Expose port 8000

EXPOSE 8000

Set environment variable to indicate that Django is running in the container

ENV PYTHONUNBUFFERED 1

Default command

CMD ["sh", "-c", "python wait_for_db.py && python manage.py makemigrations && python manage.py migrate && python test_connection.py && python sharepoint_to_json.py && python manage.py runserver 0.0.0.0:8000"]

I verified that the msodbcsql17 driver is installed correctly in the container. I checked the path /opt/microsoft/msodbcsql17/lib64/, but the file libmsodbcsql-17.9.so.1.1 does not seem to exist. I ensured that my odbcinst.ini is properly configured.

My Questions: Why does the driver seem to work for other scripts but fail for this particular one (sharepoint_to_json.py)? How can I fix the missing file error in my Docker setup? Is there a better way to verify if the ODBC driver is correctly installed and recognized within the container? Any guidance would be greatly appreciated!

Back to Top