So I'm running through the following:
Created a Dockerfile and a docker-compose.yml to develop a django app locally, nothing to do here, everything works just fine.
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/All it does is fetches python3 image, copies the code from my source folder to the docker image
Then I'm trying to deploy this to heroku, so I added postgres add-on on heroku apps, and configured it using dj_database_url, with the following command on my settings.py file :
DATABASES = {} DATABASES['default'] = dj_database_url.config()
After that I pushed my application to heroku using
heroku container:push web
and it got pushed to my app no problem at all...The final piece is when I open my application using
heroku open
it says I got an error:Application error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.
This is what get printed on the heroku website
Now, when I log using
heroku logs -t
, it says that exited with code 0, then it crashes
What am I missing?
- Plus: when I run
heroku run web python manage.py migrate
it migrates the data on the heroku app - Plus 2: when I run
heroku run web python manage.py runserver
it says is running on 127.0.0.1:8000
EDIT 1: If you want to reproduce the problem you can clone all my code in the following git repo: https://github.com/giovanniKleinCampigoto/djangoherokuproblem.git
EDIT 2:
In this official tutorial: https://devcenter.heroku.com/articles/deploying-python , says to use virtualenv, but I'm using docker, so I don't really know how to proceed...
EDIT 3:
Also, I noticed that when I push the image to heroku using: heroku container:push web, the server re-deploys, but instead of running whatever is on the procfile it just logs this:
Starting process with command python3
]
EDIT 4:
When running heroku local web
, and editing the Procfile to run docker-compose up
works just fine, the problem is with the upload to heroku's server...not sure if I should edit the file to just python manage.py runserver...
docker-compose.yml
version: '2'
services:
web:
build: .
env_file: composeexample/.env
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"