Deploy Django Docker Compose to Heroku

To deploy a Django project that uses Docker Compose to Heroku, you will need to make a few changes to your project.

First, create a Procfile at the root of your project directory and add the following line:

web: gunicorn myproject.wsgi

This t…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Gerard Nwazk

To deploy a Django project that uses Docker Compose to Heroku, you will need to make a few changes to your project.

First, create a Procfile at the root of your project directory and add the following line:

web: gunicorn myproject.wsgi

This tells Heroku to use the gunicorn web server to run your Django app. Replace myproject with the name of your Django project.

Next, create a requirements.txt file that lists the Python packages that your app depends on. You can generate this file by running the following command:

$ pip freeze > requirements.txt

You will also need to modify your Dockerfile to use the gunicorn web server instead of the Django development server. Here is an example Dockerfile that you can use:

FROM python:3.8

ENV PYTHONUNBUFFERED 1

RUN mkdir /app
WORKDIR /app

COPY requirements.txt /app/
RUN pip install -r requirements.txt

COPY . /app/

CMD gunicorn myproject.wsgi --bind 0.0.0.0:$PORT

Make sure to replace myproject with the name of your Django project.

Finally, you will need to create a heroku.yml file at the root of your project directory with the following contents:

build:
  docker:
    web: Dockerfile
  heroku:
    app: myapp
    stack: container

run:
  web: docker-compose up

Replace myapp with the name of your Heroku app.

To deploy your app to Heroku, make sure you have the Heroku CLI installed, and then run the following commands:

$ heroku login
$ git init
$ git add .
$ git commit -m "Initial commit"
$ heroku create
$ git push heroku main

This will build and push your Docker image to Heroku, and start the app.
Happy coding...


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Gerard Nwazk


Print Share Comment Cite Upload Translate Updates
APA

Gerard Nwazk | Sciencx (2023-01-06T23:13:29+00:00) Deploy Django Docker Compose to Heroku. Retrieved from https://www.scien.cx/2023/01/06/deploy-django-docker-compose-to-heroku/

MLA
" » Deploy Django Docker Compose to Heroku." Gerard Nwazk | Sciencx - Friday January 6, 2023, https://www.scien.cx/2023/01/06/deploy-django-docker-compose-to-heroku/
HARVARD
Gerard Nwazk | Sciencx Friday January 6, 2023 » Deploy Django Docker Compose to Heroku., viewed ,<https://www.scien.cx/2023/01/06/deploy-django-docker-compose-to-heroku/>
VANCOUVER
Gerard Nwazk | Sciencx - » Deploy Django Docker Compose to Heroku. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/01/06/deploy-django-docker-compose-to-heroku/
CHICAGO
" » Deploy Django Docker Compose to Heroku." Gerard Nwazk | Sciencx - Accessed . https://www.scien.cx/2023/01/06/deploy-django-docker-compose-to-heroku/
IEEE
" » Deploy Django Docker Compose to Heroku." Gerard Nwazk | Sciencx [Online]. Available: https://www.scien.cx/2023/01/06/deploy-django-docker-compose-to-heroku/. [Accessed: ]
rf:citation
» Deploy Django Docker Compose to Heroku | Gerard Nwazk | Sciencx | https://www.scien.cx/2023/01/06/deploy-django-docker-compose-to-heroku/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.