容器化现有django应用程序所需的指导,该应用程序已连接到SQL Server的现有docker映像。
我不明白如何编写一个docker-compose文件,该文件具有将连接到现有sql server数据库映像的数据库条目。
sql_server映像在端口1433上运行,访问URL为localhost:1433。从虚拟环境运行时,我可以连接到服务器,并且应用程序运行正常。
这是Dockerfile ...
FROM python:3
ENV PYTHONUNBUFFERED 1
# Project Files / Settings
RUN mkdir /sch
WORKDIR /sch
ADD . /sch
# Install libraries, dependencies
RUN apt-get autoremove && apt-get autoclean && apt-get update && apt-get install -y gcc unixodbc-dev
RUN pip3 install pyodbc
RUN pip3 install django-pyodbc-azure
RUN pip3 install -r requirements.txt
# Server
EXPOSE 8003
STOPSIGNAL SIGINT
ENTRYPOINT ["python", "manage.py"]
CMD ["/web/manage.py", "runserver", "0.0.0.0:8003"]
这是docker-compose文件
version: '3'
services:
web:
build: .
command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8003"
container_name: sch
volumes:
- .:/sch
ports:
- "8003:8003"
现在,我得到的错误是...
ModuleNotFoundError: No module named 'sql_server'
django.core.exceptions.ImproperlyConfigured: 'sql_server.pyodbc' isn't an available database backend.