Deploy Django Docker Image to Heroku
Вставка
- Опубліковано 9 лют 2025
- In this tutorial I walk you through the process of setting up a Django Docker image and deploy to a Heroku container. Through this process we Create a new project, configure Django with AWS S3 storage, configure Environment variables and Settings granularization. We then move towards Creating a Dockerfile / test / upload to Docker Hub. After which we then deploy a docker Image to Heroku and set the environment variables.
00:00 Introduction
03:45 Start a Django Application
05:15 Introducing Environment variables
18:15 Introduction to Settings granularisation
23:59 Setup AWS S3 storage
41:24 Create Dockerfile for project
55:32 Upload docker image to Docker Hub
58:02 Deploying image to Heroku
01:04:40 Heroku CLI commands
Code Repository:
github.com/ver...
👍SUBSCRIBE to get more free tutorials, courses and code snippets!
/ @veryacademy
👍👍Follow us on Facebook
/ veryacademycom-1132321...
👍👍👍Follow use on Twitter:
/ veryacademy
Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. This video is intended to be a independent and non affiliated tutorial helping you to better understand the Docker software. We are not accredited, certified, affiliated or endorsing Docker, Inc.
Wow this is exactly what I was searching for. Thank you!
Great! Good luck with it - honestly there is a few things that might cause issues - just start small and grow (if your not to familiar with it). I was going to do a more complicated build but this way you get it working first before applying to a bigger project. 👍
a tip: you can watch series at InstaFlixxer. I've been using them for watching a lot of movies lately.
@Major Kai yea, been watching on instaflixxer for since november myself =)
It is was what I look for : config environment variables, great job!
Glad it helped!
Thanks so much man, helped fill in some holes from some other sources.
Great work.... meticulous, easy speed and well thought out.. Thanks
Glad you liked it!
Thanks for this. I love the detail. Helped me a lot.
Awesome as always 🙂👍
Hey Ranga, thank you, hope you are well 👍
@@veryacademy 👍😀
Your video is simply amazing. Thank you very much for sharing, I am subscribing
amazing demo, thnx a lot
You are welcome!
Could you do a tutorial on deploying django app on a server like vpsdime or ssdnodes with database and docker? I know it seems too much to ask for, but I can learn much easily from your tutorials and they're really helpful.
Can you please do almost the same thing but with docker-compose file with postgres and volume. then deploy to heroku
At 49:59 you said that the dockerfile is done, I thought we need to add in a volume so that the database will save data permanently? There is no volume in this dockerfile, right? I have another question. How do you update code in Heroku? If you fixed a bug, do you rebuild the image with updated code then push to heroku the same way you did in this video? Thanks.
Lots of question there. I don't think I went that extra step here to include a database - Think I did go on in another to show you? Update code in Heroku, presume you mean if you are using Docker. Well you might be best off updating your image and redeploy it. With Heroku you could setup a pipeline in GitHub actions for example to rebuild image and deploy directly to Heroku every time you push to your repository. In short - develop on your machine - push you GitHub - having GitHub action create image and deploy to Heroku. Use a separate instance for your database.
@@veryacademy Thank you.
the environment variable don't work with me at all, I have .bash_profile fie and I made .env file,
can os.getenv() find the environment variable files anywhere, or should I specify their directories
Hi Ali, there seems to be a few issues with this reported to me - I will get on a create an update for this. Will try and get it done today or tomorrow.
Wonderful content.
I have been following your guide but you are deploying just a Django image to Heroku, but initially you Dockerized Celery, Redis, and Django, how do we deploy that to Heroku.
If you can assist with that, thank you.
Hi Ikenna, it will be a similar process. You have everything inside the containers. With Heroku and many other providers you have many options. Do you for example use Heroku Redis and DB service instead of dockerizing it. So I guess that is the question I propose to you - would you like to deploy it all in a container or consider in the case of Heroku using their other services - Please avoid returning with (what do you think is best 😁) I cant answer that for your project and setup
@@veryacademy Lol, I have used the Heroku Redis and DB service it's working okay, However, Celery and beat aren't working, wondering if there is a different config for the Dockerfile in deploying to Heroku.
Thank you!
Hi Kevin, thank you - hopefully some value.
@@veryacademy Yeah of course man every single time! Thanks again and hope you're feeling better.
I have watched deploying django and react to Heroku and this video. Could you possible to teach me how to deploy django , react , docker to heroku?
dev.to/mdrhmn/deploying-react-django-app-using-heroku-2gfa
Is it possible to deploy Django Docker Image to Heroku using Postgresql database without docker-compose? if yes, how do i do that please? and if its not possible, how do i inject environmental variables to heroku for docker-compose file? thanks
Could you make a video on integrating with circle ci using docker, it would be very helpful. Thanks.
Great suggestion! Thank you - I have noted it down on the list - cant promise when
@@veryacademy okay would be looking forward to it. Love your vids
Thank you for the tutorial!
Is there any chance, that you would make a video about the dhango-react deployment to Heroku using containers?
That is a great suggestion. I will be adding some more to these tutorials. We need to also add a DB and Redis etc. Yeah ok - am on it. Thank you!
@@veryacademy Thanks for the reply :) I've already managed to do it by myself, but looking forward to watch the video anyways
btw do you have any experience with integrating websockets into existing DRF application (e.g. using channels if that's even possible)? would be super cool to see such a tutorial on your channel :)
Such great tutorials and thank you so so so much!!! couldn't stop and watched all videos, any place to make a donation?
The project with Django, pgdb, celery, and Redis is really a nice combination, just wondering if this serial has been over or there are more videos on deploying that previous project? Or even with gunicorn + Nginx? Sorry to ask for more, your tutorials are really anticipated
Thank you Ichii, everything around here is just starting! There will be plenty more tutorials on everything, including this series. I think I am doing another Django Heroku with docker compose next. But happy to take suggestions. No need to donate, it’s all free, we do have a members option on the UA-cam channel if you would like to join for a small cost 👍
Can this be applied to a django+react app?
its a little different with React
Why you didn't use docker-compose ?
Hi Tousif, thank you for the suggestion. I didnt need to use it just to create a simple docker image without other dependencies. 👍
Great video! Question - just wondering... Before watching this docker series I would "obviously" (LOL) start my django project with pipenv and skip the requirements.text. Do you have any thoughts about pipenv? It's use with django and docker?
medium.com/telnyx-engineering/rip-pipenv-tried-too-hard-do-what-you-need-with-pip-tools-d500edc161d4#:~:text=Pipenv%20is%20dead.,and%20a%20complicated%20release%20process%E2%80%9D.
@@veryacademy Very cool. Thanks.
sudo docker run -p 8000:8000 django-final_year:v1
returns
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "gunicorn": executable file not found in $PATH: unknown.
ERRO[0008] error waiting for container: context canceled
please help
Nice Tutorials 👍🏼 can u make one on Fastapi too?
Hey vg - there is a plan to for sure. I have Graphene-Django lined up next then could do Fastapi. 👍
please make a video on serverless django in cloud run
Noted. if there is no server where are you going to host it? (Just joking of course) Why we couldnt come up with a better name for it.
Actually setting env variable as DEBUG=False doesnt work, as they are parsed as string. And by default the value of any non empty string is true. Thus we need to perform string matching to make debug=false work, if we set is as env variable.
te quiero con toda mi alma y todo mi corazón
I got error ERROR [3/5] RUN set-ex && pip install --upgrade pip && pip install --no-c 1.1s
executor failed running [/bin/sh -c set-ex && pip install --upgrade pip && pip install --no-cache-dir -r /2021-02-18/requirements.txt]: exit code: 127
Guy anyone please help me how to rectify?
Do you run python or py at the start of your commands - try py - you might have multiple versions of Python installed which could be the problem here
@@veryacademy As per you instruction i do same as python/python3/py. however could not rectify; here drop error message please find
=> ERROR [3/5] RUN set-ex && python3 pip install --upgrade pip && python3 pip install --no-cache-dir -r /2021-02-18/requirements.txt 0.4s
------
> [3/5] RUN set-ex && python3 pip install --upgrade pip && python3 pip install --no-cache-dir -r /2021-02-18_Redcarbet/requirements.txt:
#7 0.372 /bin/sh: set-ex: not found
------
executor failed running [/bin/sh -c set-ex && python3 pip install --upgrade pip && python3 pip install --no-cache-dir -r /2021-02-18/requirements.txt]: exit code: 127
"gunnyhorn"
😂👍