Deploying app in containers as microservices has its own pro's and cons. For a good understanding of the role of Containers in MicroServices, Read this article. In this blog post we will look into deploying a sample Django app into a docker container.
Creating Sample Django project:
sudo apt-get install python-dev python-pip python-virtualenv mkdir /webapps && cd /webapps virtualenv env source /webapps/env/bin/activate pip install django django-admin.py startproject testapp
now that you have a sample django project, copy /webapps/testapp to a folder called web where we will build Docker APP. the folder structure should be
`-- <some-folder> |-- Dockerfile |-- web `--scripts |-- testapp |-- confs
You can prehandedly prepare a docker image that contains all your system apt/yum requirements or write a script that can install it on runtime and save it in scripts folder.
Prepare a <project-home>/scripts/project_setup.sh and give it execution permission and include your confs files like gunicorn, uwsgi, supervisor,nginx files. Build a shell script that does the rest of processing for you.
FROM ubuntu:latest ENV APP_NAME=testapp ENV DJANGO_SOURCE=web ENV PROJECT_HOME=/webapps/$APP_NAME RUN mkdir -p $PROJECT_HOME COPY $DJANGO_SOURCE $PROJECT_HOME RUN $PROJECT_HOME/scripts/project_setup.sh ENTRYPOINT ["/<some-script that starts required services>"]
docker build -t <image-name> .
Now Deploy your app with standard DOcker run command.
Docker run -d <image-name>
Micropyramid is a software development and cloud consulting partner for enterprise businesses across the world. We work on python, Django, Salesforce, Angular, Reactjs, React Native, MySQL, PostgreSQL, Docker, Linux, Ansible, git, amazon web services. We are Amazon and salesforce consulting partner with 5 years of cloud architect experience. We develop e-commerce, retail, banking, machine learning, CMS, CRM web and mobile applications.
Django-CRM :Customer relationship management based on Django
Django-blog-it : django blog with complete customization and ready to use with one click installer Edit
Django-webpacker : A django compressor tool
Django-MFA : Multi Factor Authentication
Docker-box : Web Interface to manage full blown docker containers and imagesMore...