Fabio Bove
Fabio Bove

Reputation: 51

Dockerized Django App - Login timeout connecting to SQL Server Database ODBC Driver 17

I'm trying to connect my Django application, running in a container, to a SQL Server.

I've read many different topics but none of the provided solutions works in my case, can you please help me with any suggestions or hint that you have?

If I run the Django app from my local machine everything works, but when I use the containerized version I get the error:

('HYT00', '[HYT00] [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')

The configurations of the settings are the following, and they work on the non-containerized version:

    'secondary': {
        "ENGINE": "mssql",
        "HOST":"0.0.0.0,1433",
        "NAME": "db_name",
        "USER":  "sa",
        "PASSWORD": "pwd",
        "PORT": "",
        "OPTIONS": {
            'driver': 'ODBC Driver 17 for SQL Server',
        }
    }

The Dockerfile I'm using is like:

# Use an official Python runtime as a parent image
FROM python:3.9

# Install ODBC Driver 17 for SQL Server
RUN apt-get update && \
    apt-get install -y curl && \
    curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
    curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
    apt-get update && \
    ACCEPT_EULA=Y apt-get install -y msodbcsql17


# Set the working directory
WORKDIR /app

# Install Python dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt

# Copy the rest of your application code into the container
COPY . .

EXPOSE 8000

#RUN your Django application
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

Thanks in advance

Upvotes: 1

Views: 303

Answers (0)

Related Questions