Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install ODBC driver in Alpine Linux Docker Container

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?

like image 620
Alexis.Rolland Avatar asked Aug 17 '18 03:08

Alexis.Rolland


People also ask

How can I install Docker inside an Alpine container?

To install Docker on Alpine Linux, run apk add --update docker openrc. The Docker package is available in the Community repository. Therefore, if apk add fails because of unsatisfiable constraints error, you need to edit the /etc/apk/repositories file to add (or uncomment) a line.

Is there an ODBC SQL Server Driver for a docker image?

I ended up with another resolution which defines the ODBC SQL Server Driver specifically for an Ubuntu 18.04 Docker image, in this case ODBC Driver 17 for SQL Server. In my specific use case I needed to make the connection to my MySQL database server on Azure via Flask SQLAlchemy, but the latter is not a necessity for the Docker configuration.

Where can I find the Microsoft ODBC driver on Linux?

The driver and its support files must be in /opt/microsoft/msodbcsql/11.0.2270.0. To verify that the Microsoft ODBC driver on Linux was registered successfully, execute the following command: odbcinst -q -d -n "ODBC Driver 11 for SQL Server".

How to deploy MS sqlServer 2016 on Linux using Docker?

Connect to SQL Server Linux on Docker via ODBC Driver. Introduction. Now that SQLServer 2016 is available on Linux as a public preview, one of the easiest ways to officially deploy it is through Docker engine. With the Docker image of MS SQLServer on Linux, you will have a running instance within few seconds.

Why can’t I connect to SQL Server using the ODBC driver?

If you are unable to make a connection to SQL Server using the ODBC driver, use the following information to identify the problem. The most common connection problem is to have two copies of the UnixODBC Driver Manager installed. Search /usr for libodbc*.so*.


Video Answer


1 Answers

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
like image 61
Shubham Patel Avatar answered Sep 20 '22 19:09

Shubham Patel