【发布时间】:2020-03-16 15:43:07
【问题描述】:
我正在尝试使用他们的容器解决方案应用服务在 microsoft azure 上传 django 应用。 没有 docker 的 APP 运行良好,在我添加 docker 后它在本地运行,但是当我使用 microsoft 容器注册表并将其上传到然后尝试将其应用程序用于容器解决方案时,它不起作用。我需要一些帮助:
我创建了基本的 django restapiframework。里面没有添加任何东西。 之后,我检查了它是否在本地工作并且工作正常。 之后,我将它上传到 microsoft azure web 应用程序(不适用于 cointaners),它运行良好。 之后,我尝试将 docker 添加到我的项目中,并将 microsoft azure web services 用于容器。
以下是我尝试在本地使用的 docker 代码和命令:
DockerCompose:
version: '3.7'
services:
web:
build: .
command: bash -c "python manage.py makemigrations && python manage.py migrate --run-syncdb && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
volumes:
- ./django_dashboard:/usr/src/django_dashboard
ports:
- 8000:8000
env_file:
- ./.env.dev
Docker 文件:
FROM python:3.6
# set work directory
WORKDIR /usr/src
# install dependencies
RUN pip install --upgrade pip
COPY requirements.txt /usr/src/requirements.txt
RUN pip install -r requirements.txt
# set work directory
WORKDIR /usr/src/django_dashboard
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1 #Prevents Python from writing pyc files to disc (like python -B)
ENV PYTHONUNBUFFERED 1 #Prevents Python from buffering stdout and stderr (like python -u)
# copy project
COPY . /usr/src/django_dashboard/
我的文件树
├── backend
│ └── django_dashboard
│ ├── db.sqlite3
│ ├── django_dashboard
│ │ ├── asgi.py
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ │ ├── __init__.cpython-36.pyc
│ │ │ ├── settings.cpython-36.pyc
│ │ │ ├── urls.cpython-36.pyc
│ │ │ └── wsgi.cpython-36.pyc
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── Dockerfile
│ ├── __init__.py
│ ├── manage.py
│ ├── requirements.txt
│ └── rest
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── models.py
│ ├── __pycache__
│ │ ├── admin.cpython-36.pyc
│ │ ├── __init__.cpython-36.pyc
│ │ ├── models.cpython-36.pyc
│ │ ├── serializers.cpython-36.pyc
│ │ └── views.cpython-36.pyc
│ ├── serializers.py
│ ├── tests.py
│ └── views.py
├── docker-compose.yml
├── frontend
│ ├── Dockerfile
│ ├── package.json
│ ├── public
│ │ ├── favicon.ico
│ │ └── index.html
│ ├── README.md
│ └── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── components
│ │ └── Modal.js
│ ├── index.css
│ ├── index.js
│ └── logo.svg
└── README.md
要在本地运行它,我正在使用:
docker-compose build --no-cache
docker-compose up
接下来我尝试从他们的门户运行应用程序服务并进入日志:
2020-03-16 15:10:06.070 INFO - Starting container for site
2020-03-16 15:10:06.071 INFO - docker run -d -p 1219:8000 --name MYWEBSITE -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITES_PORT=8000 -e WEBSITE_SITE_NAME=MYWEBSITE -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=MYWEBSITE.azurewebsites.net -e WEBSITE_INSTANCE_ID=f2b41f3b5bb846770d96154839b55ad19f2b5bc4fef2a60a950ee081118ef8b0 MYWEBSITE.azurecr.io/MYWEBSITE:1v
2020-03-16 15:10:06.071 INFO - Logging is not enabled for this container.
Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2020-03-16 15:10:33.890 INFO - Initiating warmup request to container MYWEBSITE for site MYWEBSITE
2020-03-16 15:10:34.336 ERROR - Container MYWEBSITE for site MYWEBSITE has exited, failing site start
2020-03-16 15:10:34.656 ERROR - Container MYWEBSITE didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
2020-03-16 15:10:34.926 INFO - Stoping site MYWEBSITE because it failed during startup.
将网站名称替换为 MYWEBSITE
我做错了什么?谢谢你的帮助。
【问题讨论】:
-
我看到您的应用程序没有启动。您可以尝试在将映像部署到 Web 应用时使用您在 docker-compose 文件
python manage.py makemigrations && python manage.py migrate --run-syncdb && python manage.py migrate && python manage.py runserver 0.0.0.0:8000中设置的命令添加启动文件。 -
我尝试使用
#!/bin/bash python django_dashboard/manage.py makemigrations && python django_dashboard/manage.py migrate --run-syncdb && python django_dashboard/manage.py migrate && python django_dashboard/manage.py runserver 0.0.0.0:8000在主文件夹中创建文件init.sh,但它不起作用 -
Container start failed for MYWEBSITE with System.AggregateException, One or more errors occurred. (Docker API responded with status code=BadRequest, response={"message":"OCI runtime create failed: container_linux.go:345: starting container process caused \"exec: \\\"init.sh\\\": executable file not found in $PATH\": unknown"} ) (Docker API responded with status code=BadRequest, response={"message":"OCI runtime create failed: container_linux.go:345: starting container process caused \"exec: \\\"init.sh\\\": executable file not found in $PATH\": unknown"} ) -
InnerException: Docker.DotNet.DockerApiException, Docker API responded with status code=BadRequest, response={"message":"OCI runtime create failed: container_linux.go:345: starting container process caused \"exec: \\\"init.sh\\\": executable file not found in $PATH\": unknown"} -
我的意思是当你部署到网络应用时,有一个你可以设置的启动文件,它是网络应用的一个属性。
标签: python django azure docker