Sign inSign up

cymagix/python-for-pyodbc-sqlserver

By cymagix

Updated almost 4 years ago

Docker image to deploy apps on Python 3.11.1, using pyodbc 4.0.35 and ODBC Driver for MS SQL Server.

Image
0

4.8K

cymagix/python-for-pyodbc-sqlserver repository overview

python-docker-for-pyodbc-sqlserver

Docker image to deploy apps on Python 3.11.1, using pyodbc 4.0.35 and ODBC Driver for MS SQL Server.

Check the raw Dockerfile here: https://github.com/cymagix/python-docker-for-pyodbc-sqlserver/blob/main/Dockerfile

Elements

Uses official image Python 3.9.10-buster

Usage

Example of usage for Dockerfile of FastAPI app:

FROM cymagix/python-for-pyodbc-sqlserver

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir --trusted-host pypi.python.org -r requirements.txt

EXPOSE 8000
CMD ["uvicorn", "main:app", "--reload", "--host", "0.0.0.0", "--port", "8000"]

Also, in your Python code, connect as follows:

import pyodbc

def init_connection():
    config = ('Driver={ODBC Driver 17 for SQL Server};' +
                'Server=127.0.0.1,1433;' +
                'Database=yourdb;' +
                'UID=SA;' +
                'PWD=your@password;')
    connection = pyodbc.connect(config)
    return connection.cursor()

GitHub repository

https://github.com/cymagix/python-docker-for-pyodbc-sqlserver

Tag summary

Content type

Image

Digest

sha256:533d616a7

Size

422.3 MB

Last updated

almost 4 years ago

docker pull cymagix/python-for-pyodbc-sqlserver