Docker pyodbc

I am having issue while using docker.
My app uses a lot of connections to SQLServer with:
pyodbc.connect(‘DRIVER={SQL Server};SERVER=’+server+‘;DATABASE=’+database+‘;UID=’+username+‘;PWD=’+ password)

I was able to deploy the app to docker, but when running it complains about the drivers.
I tried this link, but it does not work:

this is the error i am getting:
Error: (‘01000’, “[01000] [unixODBC][Driver Manager]Can’t open lib ‘SQL Server’ : file not found (0) (SQLDriverConnect)”)

i also tried DRIVER={ODBC Driver 17 for SQL Server} but it does not work either

this is my docker-compose:

version: "3.9"

services:
  cortes: 
    build: 
      context: .

    ports:
      - 8088:8088

    volumes:
      - .:/cortes

    command: >
      sh -c "python -m streamlit run app.py"

  sqlserver:
    image: mcr.microsoft.com/mssql/server:2019-latest
    environment:
      SA_PASSWORD: "Ca18"
      ACCEPT_EULA: "Y"
      MSSQL_PID: "Standard"
    ports:
      - "1433:1433"

  mssqltools:
    image: mcr.microsoft.com/mssql-tools
    depends_on:
      - sqlserver

and this is my dockerfile:

FROM python:3.9

COPY ./requirements.txt /tmp/requirements.txt
COPY . /cortes

WORKDIR /cortes

RUN python -m venv /py && \
    pip install --upgrade pip && \
    apt-get install libpq-dev gcc && \
    pip install -r /tmp/requirements.txt && \
    rm -rf /tmp

EXPOSE 8088

Yes!! i finally figured it out by adding this to dockerfile:

RUN apt-get update \
 && apt-get install --yes --no-install-recommends \
        apt-transport-https \
        curl \
        gnupg \
        unixodbc-dev \
 && 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 --yes --no-install-recommends msodbcsql17 \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/* \
 && rm -rf /tmp/*
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.