Eu quero criar um container python3 que consiga se conectar em um SQLSERVER, estou usando o Django na minha aplicação e ele não possui um driver nativo para fazer essa conexão. Criei uma imagem para já deixar configurado o python3 com os respectivos drivers:
FROM ubuntu:19.10
# apt-get and system utilities
RUN apt-get clean && apt-get update && apt-get install -y \
curl apt-utils apt-transport-https debconf-utils gcc build-essential g++-9
# adding custom MS repository
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/19.10/prod.list > /etc/apt/sources.list.d/mssql-release.list
# install SQL Server drivers
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql17 unixodbc-dev
# install SQL Server tools
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y mssql-tools
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN /bin/bash -c "source ~/.bashrc"
# python libraries
RUN apt-get update && apt-get install -y \
python3.6 python3-pip python3-dev python3-setuptools \
--no-install-recommends
# install necessary locales
RUN apt-get update && apt-get install -y locales \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& locale-gen
RUN pip3 install --upgrade pip
# install SQL Server Python SQL Server connector module - pyodbc
RUN pip3 install pyodbc
E o dockerfile, que usa a imagem construida acima, da aplicação é:
FROM matheusrbarbosa/python3-mssql
RUN mkdir app
COPY . /app
RUN apt-get update
RUN pip3 install -r app/requirements.txt
EXPOSE 8000
WORKDIR /app/webservice/
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
E as configurações no settings.py
é
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': DB_NAME,
'USER': DB_USERNAME,
'PASSWORD': DB_PASSWORD,
'HOST': DB_HOST,
'PORT': 1433,
}
}
Sendo que os valores da conexão são passados por variaveis de ambiente...
O problema é que eu já tentei de tudo para fazer o driver dessa conexão funcionar, e não obtive sucesso. O erro de driver é:
('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (0) (SQLDriverConnect)")
pyodbc.connect()
?