Docker ubuntu 20 unable to install msodbcsql17 or 13 SQL SERVer odbc Driver 13 or 17

1.4k views Asked by At

unfortunately I'm a bit desperate. I have created a dockerimage and am running everything with docker-compose. If i run docker-compose up i get this error:

| django.core.exceptions.ImproperlyConfigured: 'mssql' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of: web_1 | 'mysql', 'oracle', 'postgresql', 'sqlite3'

if i see in the pip list, i see to less packages.

:( docker-compose run web pip list

Package    Version
---------- -------
asgiref    3.5.2
Django     4.0.4
pip        22.0.4
psycopg2   2.9.3
setuptools 58.1.0
sqlparse   0.4.2
wheel      0.37.1
´´´

Dockerfile

FROM ubuntu:20.04
FROM python:3
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/

RUN apt update -y && apt upgrade -< && apt-get update
RUN apt-get install -y pip curl git python3-pip openjdk-8-jdk unixodbc-dev
#RUN pip install --upgrade pip

RUN pip install -r requirements.txt

#ADD SQL SERVER ODBC Driver 17 for Ubuntu 20.04
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

RUN ACCEPT_EULA=Y apt-get install -y --allow-unauthenticated msodbcsql17
RUN ACCEPT_EULA=Y apt-get install -y --allow-unauthenticated mssql-tools
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
COPY . /code/

´´´

requirements.txt

Django>=4.0
psycopg2>=2.8
django-mssql==1.8
djangorestframework==3.13.1
pymssql==2.2.3
pyodbc==4.0.32
pyparsing==3.0.4
setuptools==61.2.0
sqlparse==0.4.1

´´´

docker-compose.yml

version: "3"

services:
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"

1

There are 1 answers

0
Paddymaster On

docker-compose up build -d

This builds the compose new. Then i get easy errors to fix. Just change some lines in Dockerfile.

Also change in requirements django-mssql into mssql-django