This docker image may come in handy if your're trying to connect to a Microsoft SQL Server from your Python application using PyODBC and the FreeTDS driver.
Basically this image does three things:
- Install the dependencies needed to build PyODBC as described in the docs
- Download and build the FreeTDS driver as described here
- Edit
/etc/odbcinst.ini
to point at our newly built driver
The straight forward use case of this image is to install PyODBC, add your application and run it:
FROM protolab/python-freetds
WORKDIR /usr/src/app
# I'm assuming your requirements.txt contains pyodbc
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "app.py"]
In your Python code you can connect to any SQL Server using the FreeTDS driver:
connection = pyodbc.connect(driver='{FreeTDS}',
server='servername',
uid='username',
pwd='password')
The version of the FreeTDS driver to download and build. The image will try to download the corresponding tarball from ftp://ftp.freetds.org/pub/freetds/stable/. Make sure the version you specify exists. Default: 1.00