Nginx завершает работу с кодом состояния 127, но перед этим выводит: /bin/sh: python: не найден
Я создаю веб-приложение с помощью python, nginx и gunicorn. Команда docker-compose build
работает нормально, но когда я запускаю собранный образ как контейнер, я получаю следующий результат:
root@ubuntuos:/home/eliot/Documents/development/python/projects/BarAPI/JustPub# docker-compose up
Creating network "justpub_default" with the default driver
Creating justpub_db_1 ... done
Creating justpub_web_1 ... done
Creating justpub_nginx_1 ... done
Attaching to justpub_db_1, justpub_web_1, justpub_nginx_1
nginx_1 | /bin/sh: python: not found
db_1 |
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1 |
db_1 | 2022-06-19 14:08:35.192 UTC [1] LOG: starting PostgreSQL 13.0 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.3.0) 9.3.0, 64-bit
db_1 | 2022-06-19 14:08:35.192 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2022-06-19 14:08:35.192 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2022-06-19 14:08:35.196 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2022-06-19 14:08:35.200 UTC [22] LOG: database system was shut down at 2022-06-19 14:08:26 UTC
db_1 | 2022-06-19 14:08:35.204 UTC [1] LOG: database system is ready to accept connections
justpub_nginx_1 exited with code 127
web_1 | [2022-06-19 14:08:36 +0000] [1] [INFO] Starting gunicorn 20.1.0
web_1 | [2022-06-19 14:08:36 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
web_1 | [2022-06-19 14:08:36 +0000] [1] [INFO] Using worker: sync
web_1 | [2022-06-19 14:08:36 +0000] [8] [INFO] Booting worker with pid: 8
Как видите, nginx завершает работу сразу после запуска контейнера. Как решить эту проблему?
Main Dockerfile:
FROM python:3.9.5-alpine
WORKDIR /home/JustPub
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1 .
COPY requirements.txt ./
RUN apk update && \
apk add postgresql-dev gcc python3-dev musl-dev && \
pip install --upgrade pip && \
pip install -r ./requirements.txt
COPY . .
CMD gunicorn JustPub.wsgi:application -b 0.0.0.0:8000 --reload
docker-compose.yml:
version: '3.3'
services:
web:
build: ./
volumes:
- ./:/home/JustPub/
ports:
- "8000:8000"
env_file:
- .env-dev
depends_on:
- db
nginx:
build:
context: ./nginx
dockerfile: Dockerfile
ports:
- "80:80"
depends_on:
- web
- db
volumes:
- ./static/:/static/
db:
image: postgres:13.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_DB=justpub
- POSTGRES_USER=eliot
- POSTGRES_PASSWORD=justpub_password
volumes:
postgres_data:
Nginx Dockerfile:
FROM nginx:1.22.0-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY ./nginx.conf /etc/nginx/conf.d
CMD python manage.py collectstatic --no-input
nginx.conf файл:
server {
listen 80;
location / {
proxy_pass http://web:8000
}
location /static/ {
alias /static/
}
}
А структура моего проекта:
(venv) eliot@ubuntuos:~/Documents/development/python/projects/BarAPI$ tree -I "venv|__pycache__|migrations"
.
└── JustPub
├── backup.json
├── db.sqlite3
├── docker-compose.yml
├── Dockerfile
├── justpub
├── JustPub
│ ├── asgi.py
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
├── nginx
│ ├── Dockerfile
│ └── nginx.conf
├── Pub
│ ├── admin
│ │ ├── admin_forms.py
│ │ └── __init__.py
│ ├── apps.py
│ ├── __init__.py
│ ├── middleware.py
│ ├── models.py
│ ├── rest_api
│ │ ├── __init__.py
│ │ ├── serializers
│ │ │ ├── base_serializer_mixin.py
│ │ │ ├── category_serializers.py
│ │ │ ├── dishes_serializers.py
│ │ │ ├── dishestype_serializers.py
│ │ │ └── __init__.py
│ │ ├── templates
│ │ │ ├── auth_and_logout
│ │ │ │ ├── authentication.html
│ │ │ │ └── logout.html
│ │ │ ├── drf-yasg
│ │ │ │ └── swagger-ui.html
│ │ │ └── rest_framework
│ │ │ └── api.html
│ │ ├── urls
│ │ │ ├── __init__.py
│ │ │ └── pub_rest_endpoints.py
│ │ └── views
│ │ ├── docs_view.py
│ │ ├── __init__.py
│ │ ├── pub_viewsets.py
│ │ └── user_auth_views.py
│ └── urls.py
├── requirements.txt
└── static