![](/img/trans.png)
[英]I have problem to deploy my django project with docker nginx and gunicorn
[英]Deploy Docker stack with Nginx and Gunicorn on a server with Apache
我是 Docker 和服務器主題的新手,我一點一點地學習,但我遇到了一個問題,我沒有看到太多信息,最后我求助於詢問。
我有一台服務器,上面有一個 Apache 並且我部署了幾個網站(在 PHP 和 R 中)。 我已經在 Django 中創建了一個應用程序,並且我使用 Gunicorn 和 Nginx 對其進行了 docker 化,並且在服務器上部署所述應用程序時遇到了問題,但是由於我是新手,我什至不知道是否有可能Docker 堆棧與 Nginx 和 Gunicorn 在安裝了 Apache 的服務器中...
這是 Django 項目的 Dockerfile:
FROM python:3.8-slim-buster
WORKDIR /app
COPY requirements.txt .
RUN pip3 install --upgrade pip
RUN pip3 install -r requirements.txt
COPY project /app
COPY entrypoint.sh /
ENTRYPOINT ["sh", "/entrypoint.sh"]
這是入口點:
#!/bin/sh
python manage.py migrate --no-input
python manage.py collectstatic --no-input
gunicorn project.wsgi:application --bind 0.0.0.0:8000
這是 Nginx Dockerfile:
FROM nginx:1.19.0-alpine
COPY default.conf /etc/nginx/conf.d/default.conf
這是 default.conf 文件:
upstream django {
server django_gunicorn:8000;
}
server {
listen 8080;
location / {
proxy_pass http://django;
}
location /static/ {
alias /static/;
}
}
這是 docker-compose 文件:
version: '3.8'
services:
django_gunicorn:
volumes:
- static:/static
env_file:
- .env
build:
context: .
ports:
- "8000:8000"
nginx:
build: nginx
volumes:
- static:/static
ports:
- "8080:8080"
depends_on:
- django_gunicorn
volumes:
static:
如果我在沒有 Apache 的服務器上提高堆棧,它可以工作,當我嘗試在具有 Apache 的服務器上執行此操作時,問題就來了......但我不明白這個問題......
我不知道是否需要更多信息,如果需要,很抱歉,您可以告訴我,我會盡快添加。
謝謝。
我在同樣的情況下按照本教程學習 Dockerizing Django 並面臨同樣的問題。
修改Django項目的Dockerfile:
COPY ./entrypoint.sh /
到COPY./entrypoint.sh.
為我工作。 希望對你也有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.