So long story short, I'm trying to use docker to take my Django project to production through Heroku. This is my first ever Django project, first time using Docker as well.
Currently I'm getting an error when I try to run my image, this is my first attempt at testing that it runs just fine. I did check that it would run with gunicorn before I put it into the docker image. That worked just fine, although my website didn't look like what it was supposed to, but that's the whole point of docker right?
As of right now my website looks just fine with the classic:
(try_django) bash-3.2$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
October 15, 2020 - 18:31:48
Django version 2.2, using settings 'try_django.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Now I'm just trying to get this project deployed.
I can see that the image is created just fine:
simple-dj-docker latest 11554361b373 17 minutes ago 1.24GB
My next step is to run:
docker run -it -p 80:8888 simple-dj-docker
In return I get:
[2020-10-15 18:13:15 +0000] [6] [INFO] Starting gunicorn 20.0.4
[2020-10-15 18:13:15 +0000] [6] [INFO] Listening at: http://0.0.0.0:8888 (6)
[2020-10-15 18:13:15 +0000] [6] [INFO] Using worker: sync
[2020-10-15 18:13:15 +0000] [8] [INFO] Booting worker with pid: 8
[2020-10-15 18:13:15 +0000] [8] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/base.py", line 119, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.8/site-packages/gunicorn/util.py", line 358, in import_app
mod = importlib.import_module(module)
File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'try_django'
[2020-10-15 18:13:15 +0000] [8] [INFO] Worker exiting (pid: 8)
[2020-10-15 18:13:15 +0000] [6] [INFO] Shutting down: Master
[2020-10-15 18:13:15 +0000] [6] [INFO] Reason: Worker failed to boot.
My Tree:
(try_django) bash-3.2$ tree
.
├── Dockerfile
├── Pipfile
├── Pipfile.lock
├── README.md
├── app
│ ├── blog
│ │ ├── __init__.py
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── forms.py
│ │ ├── migrations
│ │ │ ├── 0001_initial.py
│ │ │ ├── 0002_contactmessage.py
│ │ │ ├── 0003_auto_20200910_1608.py
│ │ │ ├── 0004_auto_20200911_0410.py
│ │ │ ├── 0005_homecontactmessage.py
│ │ │ ├── 0006_auto_20200922_1940.py
│ │ │ └── __init__.py
│ │ ├── models.py
│ │ ├── templates
│ │ │ └── blog
│ │ │ ├── create.html
│ │ │ ├── delete.html
│ │ │ ├── detail.html
│ │ │ ├── form.html
│ │ │ ├── list-inline.html
│ │ │ ├── list.html
│ │ │ └── update.html
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── db.sqlite3
│ ├── manage.py
│ ├── rs_blog
│ │ ├── __init__.py
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── forms.py
│ │ ├── migrations
│ │ │ ├── 0001_initial.py
│ │ │ ├── 0002_contactmessage.py
│ │ │ ├── 0003_auto_20200911_0432.py
│ │ │ ├── 0004_auto_20200922_1940.py
│ │ │ └── __init__.py
│ │ ├── models.py
│ │ ├── templates
│ │ │ ├── form_studio.html
│ │ │ └── rs_blog
│ │ │ ├── create.html
│ │ │ ├── delete.html
│ │ │ ├── detail.html
│ │ │ ├── form.html
│ │ │ ├── list-inline.html
│ │ │ ├── list.html
│ │ │ └── update.html
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── searches
│ │ ├── __init__.py
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── migrations
│ │ │ ├── 0001_initial.py
│ │ │ └── __init__.py
│ │ ├── models.py
│ │ ├── templates
│ │ │ └── searches
│ │ │ └── view.html
│ │ ├── tests.py
│ │ └── views.py
│ ├── static
│ │ ├── css
│ │ │ ├── style_basestudio.css
│ │ │ ├── style_basetech.css
│ │ │ └── style_home.css
│ │ ├── images
│ │ │ ├── 1120.jpg
│ │ │ ├── Colorado.jpg
│ │ │ ├── IMG_9646.jpg
│ │ │ ├── beer-film.jpg
│ │ │ ├── clouds-sm.jpg
│ │ │ ├── clouds.jpg
│ │ │ ├── clouds.png
│ │ │ ├── frosty-range.jpg
│ │ │ ├── logo-dark.png
│ │ │ ├── logo.png
│ │ │ ├── logo2dark.png
│ │ │ ├── moon-sm.jpg
│ │ │ ├── moon.jpg
│ │ │ ├── moon.png
│ │ │ └── stars.jpg
│ │ └── js
│ │ └── home.js
│ ├── templates
│ │ ├── about.html
│ │ ├── about_studio.html
│ │ ├── about_tech.html
│ │ ├── base.html
│ │ ├── basestudio.html
│ │ ├── basetech.html
│ │ ├── contact_us.html
│ │ ├── form.html
│ │ ├── form_studio.html
│ │ ├── form_tech.html
│ │ ├── gallery.html
│ │ ├── home.html
│ │ ├── home_navbar.html
│ │ ├── js.html
│ │ ├── reesonstudio.html
│ │ ├── reesontech.html
│ │ └── rs_navbar.html
│ └── try_django
│ ├── __init__.py
│ ├── forms.py
│ ├── settings.py
│ ├── urls.py
│ ├── views.py
│ └── wsgi.py
├── static_cdn_test
│ ├── blank
│ │ └── blank.txt
│ ├── media
│ │ └── image
│ │ ├── Desk\ Edited.jpg
│ │ ├── Desk_Edited.jpg
│ │ ├── IMG_0581.jpg
│ │ ├── IMG_3435.HEIC
│ │ ├── IMG_9305.jpg
│ │ ├── IMG_9379.jpg
│ │ ├── IMG_9427.jpg
│ │ ├── IMG_9925.JPG
│ │ ├── Screen_Shot_2020-08-11_at_11.43.03_PM.png
│ │ ├── Screen_Shot_2020-08-11_at_11.43.03_PM_CCdYJ6B.png
│ │ ├── Screen_Shot_2020-08-11_at_11.43.03_PM_CCdYJ6B_FmfxW03.png
│ │ ├── Screen_Shot_2020-08-11_at_11.43.03_PM_CCdYJ6B_St4aVdj.png
│ │ └── Screen_Shot_2020-08-11_at_11.43.14_PM.png
│ └── static
│ ├── admin
│ │ ├── css
│ │ │ ├── autocomplete.css
│ │ │ ├── base.css
│ │ │ ├── changelists.css
│ │ │ ├── dashboard.css
│ │ │ ├── fonts.css
│ │ │ ├── forms.css
│ │ │ ├── login.css
│ │ │ ├── responsive.css
│ │ │ ├── responsive_rtl.css
│ │ │ ├── rtl.css
│ │ │ ├── vendor
│ │ │ │ └── select2
│ │ │ │ ├── LICENSE-SELECT2.md
│ │ │ │ ├── select2.css
│ │ │ │ └── select2.min.css
│ │ │ └── widgets.css
│ │ ├── fonts
│ │ │ ├── LICENSE.txt
│ │ │ ├── README.txt
│ │ │ ├── Roboto-Bold-webfont.woff
│ │ │ ├── Roboto-Light-webfont.woff
│ │ │ └── Roboto-Regular-webfont.woff
│ │ ├── img
│ │ │ ├── LICENSE
│ │ │ ├── README.txt
│ │ │ ├── calendar-icons.svg
│ │ │ ├── gis
│ │ │ │ ├── move_vertex_off.svg
│ │ │ │ └── move_vertex_on.svg
│ │ │ ├── icon-addlink.svg
│ │ │ ├── icon-alert.svg
│ │ │ ├── icon-calendar.svg
│ │ │ ├── icon-changelink.svg
│ │ │ ├── icon-clock.svg
│ │ │ ├── icon-deletelink.svg
│ │ │ ├── icon-no.svg
│ │ │ ├── icon-unknown-alt.svg
│ │ │ ├── icon-unknown.svg
│ │ │ ├── icon-viewlink.svg
│ │ │ ├── icon-yes.svg
│ │ │ ├── inline-delete.svg
│ │ │ ├── search.svg
│ │ │ ├── selector-icons.svg
│ │ │ ├── sorting-icons.svg
│ │ │ ├── tooltag-add.svg
│ │ │ └── tooltag-arrowright.svg
│ │ └── js
│ │ ├── SelectBox.js
│ │ ├── SelectFilter2.js
│ │ ├── actions.js
│ │ ├── actions.min.js
│ │ ├── admin
│ │ │ ├── DateTimeShortcuts.js
│ │ │ └── RelatedObjectLookups.js
│ │ ├── autocomplete.js
│ │ ├── calendar.js
│ │ ├── cancel.js
│ │ ├── change_form.js
│ │ ├── collapse.js
│ │ ├── collapse.min.js
│ │ ├── core.js
│ │ ├── inlines.js
│ │ ├── inlines.min.js
│ │ ├── jquery.init.js
│ │ ├── popup_response.js
│ │ ├── prepopulate.js
│ │ ├── prepopulate.min.js
│ │ ├── prepopulate_init.js
│ │ ├── timeparse.js
│ │ ├── urlify.js
│ │ └── vendor
│ │ ├── jquery
│ │ │ ├── LICENSE.txt
│ │ │ ├── jquery.js
│ │ │ └── jquery.min.js
│ │ ├── select2
│ │ │ ├── LICENSE.md
│ │ │ ├── i18n
│ │ │ │ ├── ar.js
│ │ │ │ ├── az.js
│ │ │ │ ├── bg.js
│ │ │ │ ├── ca.js
│ │ │ │ ├── cs.js
│ │ │ │ ├── da.js
│ │ │ │ ├── de.js
│ │ │ │ ├── el.js
│ │ │ │ ├── en.js
│ │ │ │ ├── es.js
│ │ │ │ ├── et.js
│ │ │ │ ├── eu.js
│ │ │ │ ├── fa.js
│ │ │ │ ├── fi.js
│ │ │ │ ├── fr.js
│ │ │ │ ├── gl.js
│ │ │ │ ├── he.js
│ │ │ │ ├── hi.js
│ │ │ │ ├── hr.js
│ │ │ │ ├── hu.js
│ │ │ │ ├── id.js
│ │ │ │ ├── is.js
│ │ │ │ ├── it.js
│ │ │ │ ├── ja.js
│ │ │ │ ├── km.js
│ │ │ │ ├── ko.js
│ │ │ │ ├── lt.js
│ │ │ │ ├── lv.js
│ │ │ │ ├── mk.js
│ │ │ │ ├── ms.js
│ │ │ │ ├── nb.js
│ │ │ │ ├── nl.js
│ │ │ │ ├── pl.js
│ │ │ │ ├── pt-BR.js
│ │ │ │ ├── pt.js
│ │ │ │ ├── ro.js
│ │ │ │ ├── ru.js
│ │ │ │ ├── sk.js
│ │ │ │ ├── sr-Cyrl.js
│ │ │ │ ├── sr.js
│ │ │ │ ├── sv.js
│ │ │ │ ├── th.js
│ │ │ │ ├── tr.js
│ │ │ │ ├── uk.js
│ │ │ │ ├── vi.js
│ │ │ │ ├── zh-CN.js
│ │ │ │ └── zh-TW.js
│ │ │ ├── select2.full.js
│ │ │ └── select2.full.min.js
│ │ └── xregexp
│ │ ├── LICENSE.txt
│ │ ├── xregexp.js
│ │ └── xregexp.min.js
│ └── blank.txt
├── try_django.sublime-project
└── try_django.sublime-workspace
My Dockerfile:
# Base Image
FROM python:3.8
# create and set working directory
RUN mkdir /app
WORKDIR /app
# Add current directory code to working directory
ADD . /app/
# set default environment variables
ENV PYTHONUNBUFFERED 1
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND=noninteractive
# set project environment variables
# grab these via Python's os.environ
# these are 100% optional here
ENV PORT=8888
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
tzdata \
python3-setuptools \
python3-pip \
python3-dev \
python3-venv \
git \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# install environment dependencies
RUN pip3 install --upgrade pip
RUN pip3 install pipenv
# Install project dependencies
RUN pipenv install --skip-lock --system --dev
EXPOSE 8888
CMD gunicorn try_django.wsgi:application --bind 0.0.0.0:$PORT
Somebody please save my life, lol, I feel like I'm so close to getting this up and running as my personal website and one of the first projects among my portfolio of coding but wow the last week of trying to figure out deployment has been brutal.