heroku[router]: at=error code=H14 desc="No web processes running" (Deploying Docker Image)

  devops, django, docker, heroku, python

So trying to deploy a docker image, these are my settings, and these are the errors i keep getting. I keep getting the error heroku[router]: at=error code=H14 desc="No web processes running".

I’ve installed posgres plugin on heroku and also have a dynos active.

docker-compose.yml:

version: "3"

services:
  {redacted}:
    build:
      context: .
    ports:
    - "8000:8000"
    volumes:
    - .:/{redacted}
    command: >
      sh -c "python manage.py wait_for_db &&
      python manage.py migrate &&
      python manage.py runserver 0.0.0.0:8000"
    environment:
      - DB_HOST={redacted}
      - DB_NAME={redacted}
      - DB_USER={redacted}
      - DB_PASS={redacted}
    depends_on:
      - db

  db:
    image: postgres:12-alpine
    environment:
      - POSTGRES_DB={redacted}
      - POSTGRES_USER={redacted}
      - POSTGRES_PASSWORD={redacted}

Dockerfile:

FROM python:3.8-alpine
MAINTAINER {redacted}

ENV PYTHONUNBUFFERED 1

COPY requirements.txt /requirements.txt
RUN apk add --update --no-cache postgresql-client
RUN apk add --update --no-cache --virtual .tmp-build-deps 
    gcc libc-dev linux-headers postgresql-dev
RUN pip install -r /requirements.txt
RUN apk del .tmp-build-deps

RUN mkdir /{redacted}
WORKDIR /{redacted}
COPY . /{redacted}

RUN adduser -D user
USER user

requirements.txt:

asgiref==3.2.10
beautifulsoup4==4.9.1
bootstrap4==0.1.0
certifi==2020.6.20
chardet==3.0.4
dj-database-url==0.5.0
djangify==1.0.0
Django==3.1
django-bootstrap4==2.2.0
django-crispy==1.8.1
django-filter==2.4.0
django-heroku==0.3.1
django-i18n==1.0.4
djangorestframework==3.12.1
djangorestframework-simplejwt==4.6.0
flake8==3.8.4
gunicorn==20.0.4
heroku==0.1.4
idna==2.10
mccabe==0.6.1
psycopg2==2.8.5
psycopg2-binary==2.8.6
pyclean==2.0.0
pycodestyle==2.6.0
pyflakes==2.2.0
PyJWT==2.0.1
python-dateutil==1.5
pytz==2020.1
PyYAML==5.3.1
requests==2.24.0
slugify==0.0.1
soupsieve==2.0.1
sqlparse==0.3.1
urllib3==1.25.10
whitenoise==5.2.0

settings.py:

from pathlib import Path
from datetime import timedelta
import django_heroku
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, "templates")
STATIC_DIR = os.path.join(BASE_DIR, "static")
MEDIA_DIR = os.path.join(BASE_DIR, "media")


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '{redacted}'
print(os.environ.get('DJANGO_SETTINGS_MODULE'))

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['{redacted}',]


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'bootstrap4',
    '{redacted}',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = '{redacted}'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = '{redacted}.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('DB_NAME'),
        'USER': os.environ.get('DB_USER'),
        'PASSWORD': os.environ.get('DB_PASS'),
        'HOST': os.environ.get('DB_HOST'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = '/static/'

STATICFILES_DIRS = [
    STATIC_DIR,
]

# media

MEDIA_ROOT = MEDIA_DIR
MEDIA_URL = '/media/'

#Activate Heroku
django_heroku.settings(locals())

Heres some additional error messages that may help:

2021-01-22T01:45:10.161205+00:00 app[api]: Deployed {redacted} ({redacted}) by user {redacted}
2021-01-22T01:45:10.161205+00:00 app[api]: Release v7 created by user {redacted}
2021-01-22T01:45:11.172895+00:00 heroku[{redacted}.1]: State changed from crashed to starting
2021-01-22T01:45:26.561807+00:00 heroku[{redacted}.1]: Starting process with command `python3`
2021-01-22T01:45:27.240409+00:00 heroku[{redacted}.1]: State changed from starting to up
2021-01-22T01:45:28.595208+00:00 heroku[{redacted}.1]: Process exited with status 0
2021-01-22T01:45:28.652052+00:00 heroku[{redacted}.1]: State changed from up to crashed
2021-01-22T01:45:28.655769+00:00 heroku[{redacted}.1]: State changed from crashed to starting

Source: Docker Questions

LEAVE A COMMENT