Connect docker python to SQL server with pyodbc

后端 未结 7 2036
迷失自我
迷失自我 2020-11-28 08:50

I\'m trying to connect a pyodbc python script running in a docker container to login to a MSSQL database I have tried all sorts of docker files, but not been able to make th

7条回答
  •  余生分开走
    2020-11-28 09:31

    How to install the necessary dependencies for pyodbc is related to the linux distribution and its version (in docker case, that is the base image of your docker image). If none of the above work for you, you can figure out the commands by trying in the docker container instance.

    First, exec into the docker container

    docker exec -it  bash
    

    Try various ways to get the distribution name and version of your linux. Then try different instructions in Install the Microsoft ODBC driver for SQL Server (Linux)

    Here is a working example for Debian 9 based images, deriving exactly as the document instructions.

    # Install pyodbc dependencies
    RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
    RUN curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
    RUN apt-get update
    RUN ACCEPT_EULA=Y apt-get -y install msodbcsql17
    RUN apt-get -y install unixodbc-dev
    RUN pip install pyodbc
    

提交回复
热议问题