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======================+
No comments:
Post a Comment