Introducing Docker

So, what is Docker?

Well, Docker is like a virtual machine (VM), but it's not. In a traditional VM setup, you would take a machine, install an operating system on that machine, and then install a hypervisor, such as VirtualBox (for more information, visit https://www.virtualbox.org) or VMware (to know more about VMware, check out http://www.vmware.com). You could then create a VM image on the hypervisor, which pretends to be a computer. This image would have its own BIOS and emulated hardware. You would then install an OS on this image. This is generally referred to as the guest OS. Once this is done, you would boot up the guest OS and then treat it like any other computer.

If you want to isolate your applications, you can create multiple guest OSes, but this can be costly:

Docker is slightly different. It is a program that you install on the host machine instead of the hypervisor. Docker can then start up an application in what is known as a container. Containers are totally isolated, just like a virtual machine. However, Docker uses the host OS instead of a guest OS:

The Docker alternative

This gives you some advantages, which are as follows:

  • Containers are not as resource-intensive as virtual machines
  • Containers can start up much faster than virtual machines

So, how does Docker do this? Well, it uses a Linux technology called namespaces. The following are the Linux namespaces:

  • pid: This is used for process isolation
  • net: This is used to manage network interfaces
  • ipc: This is used to manage interprocess communication
  • mnt: This is used to manage mount points
  • uts: This is used to isolate kernel and version identifiers

Docker uses these namespaces to isolate containers. This means that they are unaware of anything else that is running on the host OS. These containers have their own isolated process tree, their own isolated network stack, and so on.

The wonderful thing about Docker is that all of these containers can be made to interact with each other. This means that you can take lots of individual containers and stick them together to make something quite complex.

Let's use a basic Linux, Nginx, MySQL, and PHP (LNMP ) setup as an example. Normally, you would create a Linux virtual machine and then install Nginx, PHP, and MySQL on it.

With Docker, you can split up this stack with multiple containers. The most common setup would be an Nginx container with added PHP support and a MySQL container. You can then link these two containers together to give you the LNMP stack.

For example, if you wanted to update MySQL, you would just delete the MySQL container and add a new one.

Wait a second! If I delete MySQL and start it up again, would I lose all my data?

Well, that's not a problem. Docker can also create data-only containers. So, you can create a data-only container that holds all the data that MySQL writes to the disk and is totally isolated from the MySQL install.

Docker can be extremely powerful. The hardest part is figuring out how to break your complex systems down into small containers that run a single process. People are so used to thinking along the lines of working systems with multiple components, it can be hard to break out of this mindset.

All of this sounds great, but how do we use it?

Well, first of all you will need to install Docker on your system.  Docker is constantly evolving, so the best place to find out how to install it on your machine is to head on over to http://www.docker.com/community-edition.  They have a good overview of all the options available for you and all the information you need to get you up and running with a basic install.  

Once you have performed your basic install, you can check that everything is working by running docker run hello-world in your Terminal (or Command Prompt if you are on Windows).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.187.103