Created
March 14, 2022 23:20
-
-
Save BrandonDavidDee/400c3b73d6c8cda2b756a8ceaba8abac to your computer and use it in GitHub Desktop.
FastApi Python Docker file with pyodbc & ODBC Driver for SQL Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# At time of writing the python parent image uses Debian 11 | |
FROM tiangolo/uvicorn-gunicorn:python3.8-slim | |
COPY requirements.txt . | |
# Setup dependencies for pyodbc and weasyprint (cairo and pango libs) | |
RUN \ | |
apt-get update && \ | |
apt-get install -y curl build-essential unixodbc-dev g++ apt-transport-https libcairo2 libpango-1.0-0 libpangocairo-1.0-0 && \ | |
# ADD THE KEY FROM MICROSOFT | |
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \ | |
# GET THE PACKAGE | |
curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list && \ | |
# UPDATE | |
apt-get update && \ | |
# INSTALL 17 (NOT 18) | |
ACCEPT_EULA=Y apt-get install -y msodbcsql17 && \ | |
# Install dependencies | |
pip install --upgrade pip && \ | |
pip install -r requirements.txt && rm requirements.txt && \ | |
# Cleanup build dependencies | |
apt-get remove -y curl apt-transport-https debconf-utils g++ gcc rsync unixodbc-dev build-essential gnupg2 && \ | |
apt-get autoremove -y && apt-get autoclean -y | |
# RUN pip install --no-cache-dir fastapi pyodbc | |
# Your app may not be nested like this but mine is | |
COPY ./app /app/app | |
# The parent image exposes port 80 but AWS beanstalk will fail unless this is explictily set here | |
EXPOSE 80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment