Running a web application using Docker + Nginx on Ubuntu 14.04

This tutorial aims to show new and intermediate Docker users how to prototype and run a dockerized web server.
I am using Ubuntu 14.04 in this tutorial, if you would like to know more details about the installation of Docker follow this quick-start, otherwise for more details check the official documentation.

We need to install the linux-image-extra kernel package for Ubuntu Trusty and Wily. The package allows us use the aufs storage driver which allows:

– Fast container startup times.
– Efficient use of storage.
– Efficient use of memory.

Open your terminal and update the list of your packages:

Install the kernel package:

Then install apparmor:

Now go and install Docker:

Start it:

And test it like this:

If everything is ok, get the official Nginx image:

And run it while binding the guest port 80 to the host port 80:

Your container is running, but you should click on CTRL ^ to escape the running command and your container will stop running.

Let’s remove the exited container:

If you would like to run it in the background you should add the -d like this:

Now check if it is running with :

You will see:

Stp it for now:

Remove it:

We would like to set up a web page for our web server, let’s create a folder on our home directory and create a html file inside of it :

Now let’s mount the existing folder ~/html/ to the Nginx root folder which is /usr/share/nginx/html (notice the -v usage):

Now you can see your running web page at : http://127.0.0.1:80

If you would like to use the host port number 8080, just do this:

I hope this was helpful, more tutorials are coming so wait for it.

You may also like...