Deploying Wordpress blog with Django using Docker Containers.

Containers run services in an isolated environment, if we deploy our applications using containers then the host system on which these containers are running will not be affected even though the applications running within containers are being hacked.

If you don’t know about how django, wordpress blog are setup using nginx then look into: https://micropyramid.com/blog/configuring-wordpress-blog-as-sub-directory-alongside-django-in-nginx/

Wordpress blog will be running on docker container, using port forwarding we will forward wordpress container’s 80 port to host 8001 port. As usual django will be running on host system on port 8000(we can also run it as container).

Further nginx will be used as proxy server to serve these applications on port 8000 and 8001.

Install Docker:

sudo wget -qO- https://get.docker.com/ | sh

or

sudo curl -sSL https://get.docker.com/ | sh

Pull Wordpress blog image:

sudo docker pull wordpress

Setup Django:

Create a virtual environment and install django, then run it on 8000 port.

apt-get update -y && apt install -y python-virtualenv
cd /home
mkdir mysite
cd mysite
virtualenv env
. env/bin/activate
pip install django
django-admin startproject mysite
cd mysite && python manage.py runserver

Run wordpress blog container and forward port 80 to host’s 8001 port:

By default the wordpress image is configured to server wordpress on port 80. Using publish, forward 8001 port of host to 80 port of wordpress container.

docker run -d --name blog --publish 8001:80 wordpress

To see running containers execute:

docker ps

Finally setup nginx to be a proxy server for django and wordpress:

Following configurations assumes:

Django site domain name: micropyramid.com
Django port: 8000

Wordpress served on: micropyramid.com/blog
Wordpress port: 8001

In /etc/nginx/sites-available/djw.conf

server {
    listen 80;
    server_name micropyramid.com;
    location / {
        proxy_pass http://127.0.0.1:8000;
    }
    location /blog {
        proxy_pass http://127.0.0.1:8001;
    }
}

Symlink configuration and Restart nginx:

ln -s /etc/nginx/sites-available/djw.conf /etc/nginx/sites-enabled/
service nginx restart

That’s it goto micropyramid.com you should django welcome page, goto micropyramid.com/blog you should see wordpress site.

    By Posted On
SENIOR DEVELOPER at MICROPYRAMID

Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
Setting Up Gitlab container Registry on own Domain. Jagadeesh V

GitLab Container Registry is a secure and private registry for Docker images integrated completely in Gitlab. In this tutorial we will setup and use GitLab ...

Continue Reading...
Django on GAE (google app engine) Ashwin Kumar

Google App Engine (often referred to as GAE or simply App Engine) is a platform as a service (PaaS) cloud computing platform for developing and ...

Continue Reading...
TMUX - Sharing terminal between Users Jagadeesh V

More Often you wouldve come across sharing screens with applications like Teamviewer, Windows Remote Desktop Connection or remmina (if you're a linux user). But if ...

Continue Reading...
open source packages

Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
* We don't provide your email contact details to any third parties