Install ODBC driver in Alpine Linux Docker Container

Alexis.Rolland picture Alexis.Rolland · Aug 17, 2018 · Viewed 11.6k times · Source

I currently have the following Dockerfile to create my Docker image.

FROM python:3.6.6-alpine3.8

# Add dependencies for Python packages pandas, numpy and pyodbc
RUN apk add --no-cache curl gcc g++ unixodbc-dev
RUN ln -s /usr/include/locale.h /usr/include/xlocale.h

# Project files
ARG PROJECT_DIR=/srv/scripts
RUN mkdir -p $PROJECT_DIR
WORKDIR $PROJECT_DIR
COPY requirements.txt ./

# Install Python dependencies
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

I would like to include various ODBC drivers in this image so that I can use them to connect to different databases from the Python program running in my container.

  • The Python program is using Pyodbc to connect to databases.
  • The ODBC drivers I need to install are:
    • PostgreSQL
    • MySQL
    • Ms SQL Server
    • Teradata
    • Oracle
    • Hive
    • Impala

I wanted to start with PostgreSQL thinking it would be the easiest one but I could not find any package on the Alpine Linux Package manager. Do you have any idea how I should install such a driver?

Answer

Shubham Patel picture Shubham Patel · Nov 20, 2018

I was facing the same issue. I solved this issue by adding RUN apk update before RUN apk add commands.(I was using python:3.6-alpine)

Dockerfile

FROM python:3.6-alpine
RUN apk update
RUN apk add gcc libc-dev g++ libffi-dev libxml2 unixodbc-dev mariadb-dev postgresql-dev