{"id":24701746,"url":"https://github.com/hurricanemark/containerize-a-django-web-app","last_synced_at":"2026-04-09T20:48:05.350Z","repository":{"id":115764300,"uuid":"150558895","full_name":"hurricanemark/containerize-a-django-web-app","owner":"hurricanemark","description":" This article describes in small details how to transform a python web app project into a deployable docker image.  e.g. we will be practicing docker build and run a django web application exposing its port to a docker subnet.","archived":false,"fork":false,"pushed_at":"2018-09-28T19:17:28.000Z","size":1653,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-27T05:27:15.322Z","etag":null,"topics":["deployment-automation","django","docker","python37","webapp"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hurricanemark.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-27T09:04:01.000Z","updated_at":"2018-09-28T19:17:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"49073b3c-e739-41bb-bd4c-14b069c48e36","html_url":"https://github.com/hurricanemark/containerize-a-django-web-app","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2Fcontainerize-a-django-web-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2Fcontainerize-a-django-web-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2Fcontainerize-a-django-web-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2Fcontainerize-a-django-web-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hurricanemark","download_url":"https://codeload.github.com/hurricanemark/containerize-a-django-web-app/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244902924,"owners_count":20529115,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deployment-automation","django","docker","python37","webapp"],"created_at":"2025-01-27T05:25:20.662Z","updated_at":"2026-04-09T20:48:00.318Z","avatar_url":"https://github.com/hurricanemark.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Containerize A Django Python Project Stepwise\nThis article describes in small details how to transform your python web app project into a deployable docker image.\n\n\nGiven that we have a django python web app project in development environment; a sample can be found at [django web blog source](https://github.com/hurricanemark/django-web-blog-), to deploy using docker container will involve the following steps.\n\n## I.  Pre-requisites \nOn Ubuntu 16.04, install docker-ce, git, and python3.7.  \n\n\nIn most cases, you could simply run a single command (`sudo apt install docker.io`).  However, a preferable up-to-date docker-ce installation can be done with the following steps.  For once, you would have a strackable local repo reference in your environment.\n\n 1. **Setup Docker repository**\n     \n    *sudo apt-get update*\n\n    *sudo apt-get install apt-transport-https ca-certificates curl software-properties-common*\n\n    `curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -`\n\n    `sudo add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\"`\n\n 2. **Install Docker CE**\n\n    *sudo apt-get update*\n\n    *sudo apt-get install docker-ce*\n\n 3. **Verify docker installation**\n\n    *sudo docker run hello-world*\n\n 4. **Install local GIT**\n \n    *sudo apt-get update*\n\n    *sudo apt-get install git*\n\n    *git config --global user.name \"user_name\"*\n\n    *git config --global user.email \"email_id\"*    \n\u003e (Where user_name, email_id are from your GitHub registry.  If you don't have them, use local user name, and your email as references with respect to your local git settings only).\n\n\n 5. **Install Python3.7**\n\n    *sudo add-apt-repository ppa:jonathonf/python-3.7*\n\n    *sudo apt-get update*\n\n    *sudo apt-get install python3.7*\n\n    *python --version*\n\n    *sudo apt-get install -y build-essential libbz2-dev libssl-dev libreadline-dev libsqlite3-dev tk-dev*\n\n    *sudo apt-get install -y libpng-dev libfreetype6-dev*\n\n \n 6. **Pull source code from GitHub**\n\n    *mkdir -p ~/devel/django-src*\n\n    *cd ~/devel/django-src*\n\n    *git clone https://github.com/hurricanemark/django-web-blog-.git*\n\n\n## II. Build From a Base Docker Image\nUsing a python3:7:latest docker image, we will walk through the mechanic of shaping up only the essential components to run a web application inside a container.  We would of course compile the followings into a Dockerfile at a later time.  But for the sake of understanding what it takes; Let's approach with small, manual steps.\n\n 1. **Working with a docker container**\n\n\n    1.1  Pull base image:\n\n    *sudo docker pull python:3.7*\n\n    1.2  Create a docker network subnet:\n\n    *sudo docker network create --subnet=172.20.0.0/16 webblog_net*\n\n    1.3  Run container:    \n\n    *sudo docker run -it python3:7 \"/bin/sh\"*\n\n    (You should be connected to the running container now at its prompt #)\n\n    1.4  Install neccessary modules to run the web server:\n\n\n    *bash*        \n\n    *python --version*        \n\n    *pip install django*        \n\n    *pip install django-crispy-forms*\n        \n    *pip install Pillow==2.5.0*\n\n    *pip install pyvim*\n\n    *mkdir webblogserver*\n\n---\n\n![Alt text](RunningPy37Container.png)\n\n---\n    \n\n1.5 Archive the git source code for transfer to the running container:\n    \n    cd ~/devel/django-src; tar -cvf django_project.tar django_project\n    \n\n\n 1.6 Let's copy the python web application onto the running container:\n\nUsing another console, find the twelve digits CONTAIN_ID of python:3.7 and tag it.  It my case, it is `c18b73e50d08`.\n    \n    sudo docker ps | grep python:3.7\n    sudo docker cp ./django_project.tar c18b73e50d08:/webblogserver/django_project.tar\n\n\n\n\n 1.7 Now, save and tag the current snapshot of the running container:\n    \n\n    sudo docker commit -a \"Mark Nguyen \u003churricanemark@gmail.com\u003e\" -m \"Works-in-progress WebServer\" c18b73e50d08 deploy_webblog:v1\n    \n---\n\n![Alt text](DockerCommitWebBlog.png)\n\n---\n\n## III.  Deploy the Docker Image \n\n\n\n\n\nSince we are deploying to a sandbox, let's skip the production checks and proceed.  Now that we committed a snapshot, further build up should be referenced to image named `deploy_webblog:v1`.  e.g. If you exit out of the container, your work will still remain.\n\n\n\n 2.1 Test run\n\n\nLet's connect to the saved image and finish it up.\n\n        sudo docker run -d -it deploy_webblog:v1 \"/bin/bash\"\n    cd webblogserver; tar -xvf django_project.tar\n    cd django-project/django-project\n    python manage.py runserver \n\nIf all is well, we should see the server up and running.\n\n```\nroot@b92adca3e8e0:/webblogserver/django-project/django_project# python manage.py runserver\nPerforming system checks...\n\nSystem check identified no issues (0 silenced).\nSeptember 27, 2018 - 05:46:32\nDjango version 2.1.1, using settings 'django_project.settings'\nStarting development server at http://127.0.0.1:8000/\nQuit the server with CONTROL-C.\n\n```\n\n\n 2.2  Configure for deployment\n\n\nImportant note:  Please consult proper [delpoyment to production steps](https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Deployment).  Practicing engineering as close to production as you can should help avoiding surprises.  \n\n\n\nIn order to access the server inside this conainer, we need to configure django for deploy and then expose its port. \n\n    cd /webblogserver/django-project/django_project/django_project; \n\n\n    pyvim settings.py\n\nChange the folowing:\n\n[ALLOWED_HOSTS] = ['172.20.0.2', '192.168.0.17']\n\n\u003e (Where `172.20.0.2` belongs to the subnet `webblog_net` and `192.168.0.17` is the local host's ip address\ne.g.\nThe web would be accessible via\nhttp://172.20.0.2:3333/\nand http://192.168.0.17:1111)\n\n\n\nLet's run docker commit and save the running container once again.\n\n\n    python manage.py check --deploy\n\n    sudo docker commit -m \"Works-in-progress source code in place\" b92adca3e8e0 deploy_webblog:v3\n\n\nOn your local host, allow port 3333/tcp.  This enables your network to access the web app via port 3333 on your host.\n\n\n    sudo ufw allow 3333/tcp\n    sudo ufw reload\n\n\n\nFinally, run the container with exposure to subnet webblog_net and mapped port\n\n\n    sudo docker run -d -p 3333:1111 --name=webblog_app --net webblog_net --ip 172.20.0.2 -it deploy_webblog:v3 \n\nConnect to the container:\n\n\n\n    sudo docker run -it deploy_webblog:v3 '/bin/bash'\n\n    cd webblogserver/django-project/django-project\n\n    python manage.py runserver 172.19.0.2:1111\n\n\n\n\n# **Result in Chrome browser**\n\n\n---\n![Alt text](SampleWebBlog.png)\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhurricanemark%2Fcontainerize-a-django-web-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhurricanemark%2Fcontainerize-a-django-web-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhurricanemark%2Fcontainerize-a-django-web-app/lists"}