Skip to content

Commit f8aca24

Browse files
Realiseradpre-commit-ci[bot]mathbunnyru
authored
Recipe for Microsoft SQL Server (#1847)
* Recipe for Microsoft SQL Server Dockerfile with Microsoft SQL Server ODBC driver and pyodbc. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Get rid of apt-key, only install what's needed and clean up properly * Replace apt-get with apt * Switch from apt to apt-get * Use --no-install-recommends in the right place * Use simple pip install * Install pip package under jovyan Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com>
1 parent b7bdec6 commit f8aca24

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/using/recipes.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,3 +581,36 @@ FROM jupyter/scipy-notebook:85f615d5cafa
581581
RUN npm install -g ijavascript
582582
RUN ijsinstall
583583
```
584+
585+
## Add Microsoft SQL Server ODBC driver
586+
587+
The following recipe demonstrates how to add functionality to read from and write to an instance of Microsoft SQL server in your notebook.
588+
589+
```dockerfile
590+
ARG BASE_IMAGE=jupyter/tensorflow-notebook
591+
592+
FROM $BASE_IMAGE
593+
594+
USER root
595+
596+
ENV MSSQL_DRIVER "ODBC Driver 18 for SQL Server"
597+
ENV PATH="/opt/mssql-tools18/bin:${PATH}"
598+
599+
RUN apt-get update --yes && \
600+
apt-get install --yes --no-install-recommends gnupg2 && \
601+
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /usr/share/keyrings/microsoft.gpg && \
602+
apt-get purge --yes gnupg2 && \
603+
echo "deb [arch=amd64,armhf,arm64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/ubuntu/22.04/prod jammy main" > /etc/apt/sources.list.d/microsoft.list && \
604+
apt-get update --yes && \
605+
ACCEPT_EULA=Y apt-get install --yes --no-install-recommends msodbcsql18 && \
606+
apt-get clean && rm -rf /var/lib/apt/lists/*
607+
608+
# Switch back to jovyan to avoid accidental container runs as root
609+
USER ${NB_UID}
610+
611+
RUN pip install --quiet --no-cache-dir pyodbc
612+
```
613+
614+
You can now use `pyodbc` and `sqlalchemy` to interact with the database.
615+
616+
Pre-built images are hosted in the [realiserad/jupyter-docker-mssql](https://github.com/Realiserad/jupyter-docker-mssql) repository.

0 commit comments

Comments
 (0)