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.
Pyodbc
to connect to databases.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?
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.
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.
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".
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.
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*.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With