Use Docker Gunicorn Nginx to run Django in the development environment. After the server is started, you can only see the Nginx welcome interface.
Dockerfile is as follows:
django:
FROM python:3.5 ENV PYTHONUNBUFFERED 1 RUN groupadd -r django \ && useradd -r -g django django COPY ./requirements.txt /requirements.txt RUN pip install --no-cache-dir -r /requirements.txt \ && rm -rf /requirements.txt COPY ./compose/django/gunicorn.sh / RUN sed -i 's/\r//' /gunicorn.sh \ && chmod +x /gunicorn.sh \ && chown django /gunicorn.sh COPY . /app RUN chown -R django /app RUN mkdir /static RUN chown -R django /static USER django WORKDIR /app
nginx:
FROM nginx:latest ADD nginx.conf /etc/nginx/sites-enabled/django_blog.conf
gunicorn.sh
#!/bin/sh python /app/manage.py collectstatic --noinput /usr/local/bin/gunicorn blogproject.wsgi -w 4 -b 127.0.0.1:8000 --chdir=/app
nginx.conf configuration:
server { charset utf-8; listen 80 default_server; location /static { alias /app/static; } location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_pass http://127.0.0.1:8000; } }
docker-compose.yml
version: '3' services: django: build: context: . dockerfile: ./compose/django/Dockerfile command: /gunicorn.sh nginx: build: ./compose/nginx depends_on: - django ports: - "80:80"
Run command:
docker-compose build
docker-compose up
It seems that Nginx does not forward the request to Gunicorn? Please give me some advice!
Please enter the nginx container to see the location of the configuration file