我有一個Dockerfile最終運行的run.sh.
我想在埠 8000 上運行 gunicorn 并使用 nginx 在 80 到 8000 上運行代理請求。
問題是運行服務器是一個阻塞命令,它永遠不會執行nginx -g 'daemon off;'。
我能做些什么來處理這種情況?
這是run.sh檔案:
python manage.py migrate --noinput
gunicorn --bind=0.0.0.0:8000 bonit.wsgi:application &
nginx -g 'daemon off;'
而這個Dockerfile:
FROM python:3.8
# set work directory
WORKDIR /usr/src/app
# set environment varibles
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get install -y nginx supervisor build-essential gcc libc-dev libffi-dev default-libmysqlclient-dev libpq-dev
RUN apt update && apt install -y python3-pip python3-cffi python3-brotli libpango-1.0-0 libpangoft2-1.0-0
RUN pip install --upgrade pip
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
RUN adduser --disabled-password --gecos '' nginx
COPY nginx.conf /etc/nginx/nginx.conf
RUN python manage.py collectstatic --noinput
ENTRYPOINT ["sh", "/usr/src/app/run.sh"]
這是nginx.conf:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
upstream app {
server app:8000;
}
server {
listen 80;
server_name 127.0.0.1;
charset utf-8;
location /static/ {
alias /static/;
}
location / {
proxy_pass http://app;
}
}
}
uj5u.com熱心網友回復:
首先以守護行程模式啟動 nginx :
python manage.py migrate --noinput
nginx -g 'daemon on;'
gunicorn --bind=0.0.0.0:8000 bonit.wsgi:application
或者讓 gunicorn 在 nohup 中運行:
python manage.py migrate --noinput
nohup gunicorn --bind=0.0.0.0:8000 bonit.wsgi:application &
nginx -g 'daemon off;'
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/378411.html
