0

When I build image from Dockerfile:

FROM python:3.8.3-alpine as builder

WORKDIR /usr/src/app

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN apk update \
    && apk add postgresql-dev gcc python3-dev musl-dev jpeg-dev zlib-dev

RUN pip install --upgrade pip
COPY . .
COPY ./requirements.txt .

RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt


FROM python:3.8.3-alpine
# create directory for the app user
RUN mkdir -p /home/app

# create the app user
RUN addgroup -S app && adduser -S app -G app


# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

# install dependencies
RUN apk update && apk add libpq
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --no-cache /wheels/*

# copy entrypoint-prod.sh
COPY ./entrypoint.prod.sh $APP_HOME

# copy project
COPY . $APP_HOME

# chown all the files to the app user
RUN chown -R app:app $APP_HOME

# change to the app user
USER app

# run entrypoint.prod.sh
ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]

And next run containers. Show me:

web_1 | PostgreSQL started

web_1 | /home/app/web/entrypoint.prod.sh: exec: line 14: gunicorn: not found

entrypoint.prod.sh

#!/bin/sh

if [ "$DATABASE" = "postgres" ]
then
    echo "Waiting for postgres..."

    while ! nc -z $DB_HOST 5432; do
      sleep 0.1
    done

    echo "PostgreSQL started"
fi

exec "$@"

I also have a problem with nginx because when I enter the address 0.0.0.0:1337 I get an error 502 bad gateway(failed (113: Host is unreachable)). I think it is related to the problem above. docker-compose.yml

version: '3.7'

services:
  nginx:
    build: ./nginx
    ports:
      - "1337:80"
    restart: always
    networks:
      - nginx_network
    depends_on:
      - web
  web:
    build:
      context: .
      dockerfile: Dockerfile
    command: gunicorn znajdki.wsgi:application --bind 0.0.0.0:8000
    expose:
      - "8000"
    env_file:
      - ./.env.prod
    networks:
      - nginx_network
      - postgres_network
    depends_on:
      - db
  db:
    image: postgres
    volumes:
      - postgres:/var/lib/postgresql/data
    env_file:
      - ./.env.prod.db
    networks:
      - postgres_network

networks:
   nginx_network:
     driver: bridge
   postgres_network:
     driver: bridge

volumes:
  postgres:
Aleooo
  • 11
  • 7
  • Is `gunicorn` included in the `requirements.txt` line? (Do you have a `/wheels/gunicorn*.whl` file in the final image?) Are you missing the final `CMD` line from the Dockerfile that says what command to run? – David Maze Jul 28 '21 at 14:30
  • Oh nooo... I'm so stupid. I spent a few days on this. I did`t add Gunicorn to the requirements.txt . Thank you very much <3 – Aleooo Jul 28 '21 at 14:51

0 Answers0