my net house

WAHEGURU….!

Docker and it’s promises (Only hello world)

This is quite on the way thing about Docker,

You just become about the Technology that you know you are going to use a lot for rest of your life,

Ok Lets Dock…!!

Running Docker+Django on Production is bit different then running on Development server.

At production we need WSGI, But Why Wsgi.. ? Security?

Well Security is not the only thing, But it makes lot of Sense when using WSGI, Because all the Python things does not come with Development server, They may come But having WSGI with you is far better to Play anything on Apache, Nginx or on whatever, Ok WSGI is fine to have right now..

 

At present I don’t want to make things not complicated for me.

When using  Docker there are many thing those we need to look after to build our Docker Image, But if there are already available images then we can work on that and have fun to use them for our goodness.

This Guy is awesome: https://registry.hub.docker.com/u/grahamdumpleton/mod-wsgi-docker/

He provides everything you need to know about Docker and WSGI with Django all the time…

So WSGI is just like writing your Python scripts and run those on browser,..

A simple WSGI:file

<code>

def application(environ, start_response):
 status = '200 OK'
 output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
 ('Content-Length', str(len(output)))]
 start_response(status, response_headers)
return [output]

</code>

Create a <strong>new directory</strong> and save above file as wsgi.py in that directory.

Now time for <strong>Dockerization</strong>

Now in the same directory Create Dockerfile. To avoid confusion I mean to say $ nano Dockerfile

yes Dockerfile is a text file.

and add following two line:

<code>

FROM grahamdumpleton/mod-wsgi-docker:python-2.7-onbuild
CMD [ "wsgi.py" ]

</code>

The above lines of code say many things itself, (at least I believe that)

then run following two commands one by one: obviously 😉

<code>

docker build -t my-python-app .
docker run -it --rm -p 8000:80 --name my-running-app my-python-app

</code>

The Hello World WSGI application will now be accessible by pointing your browser at port 8000 on the Docker host.

http://<your-ip&gt;:8000

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: