Deploying Django with Docker Compose

    18
    43



    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/

    Resources:
    – 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

    source

    Previous articleFunny TikToks to cure your boredom
    Next articleKubernetes Ingress | Session 8 | Modernize Apps with Azure & Kubernetes

    43 COMMENTS

    1. 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?

    2. 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

    3. 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

    4. 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.