microsoft/mssql-django

[QUESTION] Windows Authentification from Docker container ?

QuentinAndre11 opened this issue · 2 comments

Hi !
I built a docker container (ubuntu:16.04, Python3.8) with (I think) the right instructions in Dockerfile, but now I think I have issues with the settings because Windows Authentification does not seem to work:

DATABASES = {
    "default": {
        "ENGINE": "mssql",
        "NAME": "my_db",
        "HOST": r"host.docker.internal\SQLEXPRESS",  
        "PORT": "51086",
        "USER": "",
        "PASSWORD": "",
        "OPTIONS": {
            "driver": "ODBC Driver 13 for SQL Server"
        }
    }
}

It raises the following error when I call any server-related command (such as python3 manage.py dbshell):

terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid 

Is it mandatory to setup a SQL Server authentification and pass it in USER and PASSWORD ? I can't use the credentials of the host machine to pass Windows Authentification ? I tried to set USER as "DOMAIN/user" (my actual user name) but it didn't work, because password is then mandatory.
My django app runs normally without Docker (with Windows Authentification or without) by replacing host.docker.internal by localhost. I made both authentifications possible and I change USER value to "sa" and PASSWORD to "unsafepassword".

Here is my whole Dockerfile:

FROM ubuntu:16.04

ENV PYTHONUNBUFFERED 1
# Works fine if a single Python process is launched
ENV PYTHONDONTWRITEBYTECODE 1

WORKDIR /app

# Update the package list and install necessary packages
RUN apt-get update && \
    apt-get install -y wget build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev  \
    libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev libffi-dev uuid-dev  \
    apt-transport-https gnupg2 curl

# Download Python 3.8.15 source (make -j {n_cpu+1})
RUN wget https://www.python.org/ftp/python/3.8.15/Python-3.8.15.tgz && \
    tar xvf Python-3.8.15.tgz && \
    cd Python-3.8.15 && \
    ./configure --enable-optimizations && \
    make -j 3 && \
    make install && \
    cd .. && \
    rm -rf Python-3.8.15 && \
    rm Python-3.8.15.tgz

# Add Python 3.8 binary path to the PATH environment variable
ENV PATH="/usr/local/bin:${PATH}"

# Install pip for Python 3.8
RUN wget https://bootstrap.pypa.io/get-pip.py && \
    python3 get-pip.py && \
    rm get-pip.py

# Download poppler and Microsoft ODBC driver (instructions at https://github.com/MicrosoftDocs/sql-docs/blob/live/docs/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server.md#13)
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
    curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
    apt-get update && \
    ACCEPT_EULA=Y apt-get install -y msodbcsql=13.0.1.0-1 mssql-tools=14.0.2.0-1 unixodbc-dev-utf16 libodbc1-utf16 \
    poppler-utils \

# Add sqlcmd binary path to the PATH environment variable
RUN ln -s /opt/mssql-tools/bin/sqlcmd-13.0.1.0 /opt/mssql-tools/bin/sqlcmd
ENV PATH="/opt/mssql-tools/bin:${PATH}"
# export PATH=$PATH:/opt/mssql-tools/bin

# requirements for dev
COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

COPY . /app/
EXPOSE 8000
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]

My docker-compose file:

version: '3'
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: web
    env_file:
      - .env
    ports:
      - "8000:8000"
    volumes:
      - .:/app

My requirements:

matplotlib
Django
pyodbc
mssql-django
django-extensions
django-debug-toolbar
whitenoise
pdfplumber
pdf2image
opencv-python-headless
geopandas
rtree
scikit-image
pyyaml
wand
mShan0 commented

I don't believe it's possible to authenticate with Windows Auth for a Linux docker image but I haven't tried it myself. There was an issue opened on the mssql-docker GitHub page that may have more info here: microsoft/mssql-docker#165

That same discussion links to this tutorial which might be relevant: https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-containers-ad-auth-adutil-tutorial?view=sql-server-ver16

mShan0 commented

Feel free to re-open this issue if you have any follow-up questions.