Dockerizing nginx

Now that we have images ready, let’s start dockerizing some applications to play with. I will start with dockerizing nginx and serve some static html content from it.

To dockerize an application, you need 2 things:

      1. The base image which will be used to build the new image from
      2. A dockerfile

Now what’s a dockerfile?

Dockerfile is a text file that describes how and what will the new image do. It contains command that you would execute normally when installing and configuring applications.

Dockerizing nginx

Now the first thing is to choose which image you want to build nginx on. I’ll choose the previously created image from Debian Wheezy.

So let’s start writing our Dockerfile…

I always put some description, the author and the usage of the image on the top, so create a new file (nginx.docker) and put:

Now this is a simple docker file which builds layers of images in these steps:

      1. A new image FROM aossama/wheezy
      2. With a maintainer details
      3. After than run these commands in a new container
      4. Then expose port 80
      5. And port 443
      6. The image should have these mount points available
      7. When the container starts, use this working directory by default
      8. Finally run nginx

Now build the new image:

And inspect the images, if the build finish successfully you should find the new image in the list.

Your image is ready to run in a container, to run it:

Inspect the new image and grep the IP address:

If you opened a browser and point to this IP address, you should see the welcome page of nginx.


  1. says

    Nice one. I have read about docker a year ago, and I thought its a good idea, yet, it wasn’t that useful to me as a developer.

    Nice article.