How to deploy a Django app to an EC2 instance using Docker Compose.
Find the blog post for this tutorial here: https://londonappdeveloper.com/deploying-django-with-docker-compose/
– uwsgi_params: https://uwsgi-docs.readthedocs.io/en/latest/Nginx.html#what-is-the-uwsgi-params-file
– Install Docker Compose: https://docs.docker.com/compose/install/
– GitHub SSH Guide: https://docs.github.com/en/[email protected]/github/authenticating-to-github/connecting-to-github-with-ssh
– Finished Source Code: https://github.com/LondonAppDeveloper/deploy-django-with-docker-compose
CHECK OUT OUR COURSES
➡️ DevOps Deployment Automation with Terraform, AWS and Docker: https://londonapp.dev/youtube-devops-aws
➡️ Deploy a Serverless Django app on Google App Engine: https://londonapp.dev/youtube-google-app-engine-serverless
➡️ Build a Backend REST API with Python & Django – Advanced: https://londonapp.dev/youtube-django-backend-advanced
➡️ Build a Backend REST API with Python & Django – Beginner: https://londonapp.dev/youtube-django-backend-beginner
➡️ Python for Absolute Beginners: https://londonapp.dev/youtube-python-beginners
00:00:00 – Introduction
00:01:22 – Requirements
00:02:26 – Creating a new project on Github
00:04:22 – Setup Docker in our project
00:14:50 – Create a Docker Compose file for running development server
00:18:42 – Create a .dockerignore file
00:22:33 – Update settings.py file so that it pulls configuration values from environment variables
00:30:04 – Add a database to use for our application
00:33:55 – Add the Postgres driver to our Django application
00:41:05 – Create a model that we can test with in Django
00:41:14 – Create a new app in our Django project to add the model to
00:48:35 – Add a wait for db command
00:56:34 – Update Docker Compose file to handle migrations and run this command before we start the app
00:59:37 – Configure our application to handle static and media files
01:02:00 – Configure our application to handle these static and media files
01:06:20 – Update settings.py to configure the locations that we created for static and media files
01:10:37 – Test our local development server
01:15:35 – Adding the uWSGI_params file
01:24:20 – Start the NGINX server
01:25:08 – Create a Docker file inside our proxy
01:27:42 – Define default environment variables
01:33:12 – Configure our Django app to run as a uWSGI service
01:59:40 – Test to ensure we can upload images in production mode
02:01:51 – Deploy to an AWS server
02:04:46 – Create a virtual machine
02:09:48 – Installing Git
02:12:49 – Update project code and push to Github
02:13:00 – Set up a deploy key
02:17:01 – Clone and run the service
02:18:07 – Add the configuration
02:19:56 – Launch our application
02:21:16 – Create a superuser to test with
this is a gem
I am getting this error "PermissionError: [Errno 13] Permission denied: '/app/vol'". Can anyone help me?
Gonna be first one disliked, but this video is waste if time. Instead of focusing on actual deployment, which you would expect googling the header topic, you get 'yet another' video on how to compose a set of containers with Django, DB and NGINX.
Deployment? Oh, yes — SSH to your host, pull it all from there and run rebuild command. Yes, from the host as well.
Where's actual deployment? Where are Github's CD jobs? Where's anything that would make this video actually match its title?
thank You very much for the class but I ran into a problem when running docker-compose build and here is response i got
Error while fetching server API version: (2, 'CreateFile', 'The system cannot find the file specified.')
 Failed to execute script docker-compose
Great tutorial! However – anyone got any pointers on how to deploy this container set-up as https with Lets Encrypt?
Thanks for taking out time to create this tutorial. This video sooo good that I had to purchase the advanced course.
Hi, very nice tutorial indeed. I have question regarding applying SSL Certificate on Nginx and expose to port 443. Do you have any working example?
Thank you very much, Mark!
It's very helpful!
How can I add cron jobs in this docker? before docker I used Django-crontab
Totally fantastic video!!! Lot of thanks!
Ultimate explanation and the integration. Thanks for such excellent presentation and work.
Why do you recommend using alpine for python? I had so much trouble getting it set up and running correctly with the latest versions of Django and python (4.0.2 and 3.10.2, respectively) that I decided to build without it and it went so much more smoothly, albeit at a larger total size (1.3gb total)
need ssl sert conf
could you help to make an example how to add SSL certs to nginx django uwsgi deploy with docker. thankyou so much
absolutely fantastic!! and I'm only at minute 43 !!!! gooooo
Please make a similar video by using Daphne, ASGI & Nginx
Hi Mark! Please let me know how to do port mapping in order to scale up this website. You just worked on admin url, anything other url doesn’t work. It say thay “Not found”.
Hi mark! Please make video on Django channels and websockets
db_1 | 2022-01-20 10:09:47.641 UTC  DETAIL: Password does not match for user "approotuser".
db_1 | Connection matched pg_hba.conf line 99: "host all all all md5"
db_1 | 2022-01-20 10:09:48.645 UTC  FATAL: password authentication failed for user "approotuser"
db_1 | 2022-01-20 10:09:48.645 UTC  DETAIL: Password does not match for user "
Hello! You didn’t tell how to resolve the issue of Not found, that happened almost in the end of video. please let me know that how to do port mapping in docker-compose-deploy.yml, only admin endpoint is working. i want to extend this website by adding more different thing. please reply and help me with it
Great video Mark, keep up the good work! I like the way you slowly explain what you do with no extra unnecessary "decorative" remarks. Hope to have a pint of beer with you sometime in London mate!
How to map this instance to an actual domain?
For some reason, the wait_for_db command is stuck in a loop even after postgres is available
I am so thankful for your video Mark. You are an excellent, EXCELLENT teacher. One of the best tutorials for CS on Youtube for any subject! Keep up the wonderful work and I will be praying for your channel to grow even more!
Great tutorial. Thanks for sharing.
Hey Mark, in my opinion one of the best tutorials on youtube. Thank u very much for your detailed explaination. This helped me a lot for our university project. kind greetings from germany
This tutorial is amazing, thank you for the content!
Thanks a lot for this, going to watch through it all and follow along this weekend
Can you tell about how to handle the "502 Bad Gateway nginx" error. server runs on a digital ocean droplet. I tried to access the server via droplets public ip
thanks. can you please do ssl par?
Thank you very much for this tutorial Mark. I suffered for more than 48 hours trying to solve the permission denied error. I had to add the line “`chown -R user:user /app“` to my Dockerfile to get rid of the error and finally fully deploy my app. I am trying to integrate SSL certificate i will report back on how it goes
I had to set the owner of the /data to the UUID of the docker user during debugging manually to proceed. Did I skip a crucial step?
Thanks for the excellent tutorial Mark. successfully tested the deployment on the production server locally but, have some problem in the development, particularly in the " MEDIA_ROOT='/vol/static/media' ", it gives me Permission denied error and was not mounted on the "/data/web", but when using " MEDIA_ROOT='vol/static/media/' ", there is no error and can saved the media in "app/app/vol/static/media" and was not mounted in "/data/web/". anyway, the production deployment was great locally, haven't tested it yet in the actual production server, thanks Mark. keep it up.
Thank you for the detailed tutorial 🙂 it helped!
This is exactly what I have been looking for. I took your "Rest API" course on Udemy and learned a lot. Thanks again.
Thanks for this wonderful tutorial. I took your course on Django API using docker Udemy, lovely course, but it could use an update. Thanks once again
Just something you didn't touch in this video. if I wanted to map the database info in case i had any problem with the container and all the info got lost I would add:
Why not using elastic beanstalk ?
Yo Mark! I purchased your advanced Django course on Udemy a couple of years ago and it's the best damn course on the subject. Perhaps the only thing missing was how to deploy the project to AWS using Docker containers, so thanks for this video! Keep up the good work, my dude.