Monday, December 8, 2014

Docker Machine [VirtualBox] Steps

1. Install Virtualbox in the Hostmachine
2. Download the "linux"  binary from the URL

   Rename the linux named binary as machine & chmod u+x machine
3. Create a virtualbox VM from the command
./machine create -d virtualbox dev
4.start  the Virtualbox  and observe the newly created vm in the virtualbox list.
5. Power on the created VM
6. Once the created VM is up, play with the docker commands
 docker run busybox echo helloworld

Friday, November 28, 2014

Dockerfile for the Django application, MySQL as database


Below steps to prepare docker image with the Django with helloworld application installed/setup, MySQL as a database


1. Save the Below dockerfile contents to the directory.

2. Build the image as sudo docker build -t django_hw_img .
(there is a . at the end).

On successful image creation, docker image will created. it will be listed in the list from the command sudo docker images

3. Run the image as 
sudo docker run -i -t -p 80:80 django_hw_img:latest /bin/bash

4. On container shell start the apache2 service service apache2 start

5.Access the application from the http://<your_host_ip_address>/helloworld/

+===================Dockerfile======================+
#################################################
# Dockerfile to build Python-Django WSGI Application Containers
# Based on Ubuntu:latest
#################################################

# Set the base image to Ubuntu
FROM ubuntu

# File Author / Maintainer
MAINTAINER surya.janardhan@gmail.com

# Update the sources list
RUN apt-get update

# Install basic applications
RUN apt-get install -y git build-essential libapache2-mod-wsgi apache2

# Install Python and Basic Python Tools
RUN apt-get install -y python python-pip

# Get pip to download and install requirements:
RUN pip install django

#install MySQL in noninteractive way
RUN export DEBIAN_FRONTEND=noninteractive
RUN apt-get -q -y install mysql-server python-mysqldb

#create the working dir and set the working directory
CMD mkdir /usr/local/share/apps
WORKDIR /usr/local/share/apps

#clone the tutorials from the github.com
RUN git clone https://github.com/Jadatravu/Tutorials /usr/local/share/apps/tutorials

# set the permissions to the app directory
CMD cd /usr/local/share/apps && chown -R www-data:www-data tutorials
WORKDIR  /usr/local/share/apps/tutorials/django_tutorials/helloworld/

# set the database for the helloworld database django_tut
RUN echo "CREATE DATABASE django_tut;" > /usr/local/share/apps/create_database.txt && service mysql start  && mysql -u root < /usr/local/share/apps/create_database.txt &&  python manage.py migrate

# Configure apache configuration for the helloworld application
RUN  echo "WSGIScriptAlias / /usr/local/share/apps/tutorials/django_tutorials/helloworld/helloworld/wsgi.py" >> /etc/apache2/apache2.conf &&  echo "WSGIPythonPath /usr/local/share/apps/tutorials/django_tutorials/helloworld/" >> /etc/apache2/apache2.conf &&  echo "<Directory /usr/local/share/apps/tutorials/django_tutorials/helloworld/>" >> /etc/apache2/apache2.conf &&  echo "<Files wsgi.py>" >> /etc/apache2/apache2.conf &&  echo "Order deny,allow" >> /etc/apache2/apache2.conf &&  echo "Require all granted" >> /etc/apache2/apache2.conf &&  echo "Satisfy Any" >> /etc/apache2/apache2.conf &&  echo "</Files>" >> /etc/apache2/apache2.conf &&  echo "</Directory>" >> /etc/apache2/apache2.conf

#expose the port
EXPOSE 80
+===================Dockerfile======================+

Wednesday, January 29, 2014

Django Static files tutorial
1. Create a Django project and app, Edit settings.py for database settings
2. Place the static files "files1.txt", "files2.txt" in the directory for example "/home/notroot/django_tut/staticfiles/sfiles"
3. create the directory files in the path for example "/home/notroot/django_tut/staticfiles/"
4. edit section  STATICFILES_DIRS in settings.py file with the value
"/home/notroot/django_tut/staticfiles/sfiles"
5. edit section in STATIC_ROOT in settings.py file with the value "/home/notroot/django_tut/staticfiles/files"
6. set the value for the variable in settings.py STATIC_URL = '/static/'
7. write a template in the template dir for example index.html
{% load staticfiles %}
  <a href="{% static 'files1.txt' %}">link1</a>
  <a href="{% static 'files2.txt' %}">link2</a>
8. update the TEMPLATE_DIRS option in the settings.py.
9. Add a view in the views.py and update urls.py file
10. In the project root folder run the command "python manage.py collectstatic"
out put would be

You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

0 static files copied, 73 unmodified.
11. run the server, access the url from the browser

http://127.0.0.1:8000/staticfiles/
  
12 Download the tutorial from the github
Note: This is compatible with django 1.5.4