Getting your feet wet with Docker and Containers

If you’re in the cloud or datacenter space, chances are you’ve been hearing about the term “containers” and “Docker” non-stop for the past few years. Ever stop and wonder what this is all about?
The purpose of this tutorial is to get your feet wet with Docker and to standardize your understanding of how Docker and Containers work.
Getting Started with Docker
Getting Docker to work on your server is quite simple. Available packages are in both deb and rpm and in many distributions it comes already in official repository and needs to be simply installed.  Once you have Docker successfully installed on your system, test it with running a hello world command:

$ docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
03f4658f8b78: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7
Status: Downloaded newer image for hello-world:latest
Hello from Docker.
This message shows that your installation appears to be working correctly.

After a successful installation, it is time to get our hands dirty. It is time to run our first container, but what is a container? And what’s so different compared to a virtual machine?
Linux containers contain applications or programs in a way that keep them isolated from the host system that they run on. Containers behave like its own machine – to the outside eye, they look like its own independent server. However, here’s where the difference comes into play: unlike a virtual machine, rather than creating and running an entire operating system within the virtualized instance, containers don’t need to replicate an entire operating system, only the individual components they need in order to operate. As you can imagine, this means less overhead, less space, and increased performance. To put this into perspective, with an ideal container set up, you can have as much as 4 to 6 times the number of server application instances as you can compared to running Xen or KVM VMs on the same hardware. You get a lot more application bang for your server buck.  
Running container with Docker
Alright. So now, we have Docker installed, and we understand what containers are…
It’s now time to run our first container with Docker! For our first container we will run Ubuntu.  So we will put this from the repository:
$ docker pull ubuntu
If you get a permission error, don’t forget to use sudo . The pull command will fetch the Ubuntu image from Docker’s official repository servers.
Once done, we can deploy a container with this OS.
$ docker run -i -t ubuntu /bin/bash
To run image we will use the command run. Type in terminal
$ docker run ubuntu ls -l
  We can verify the container was successfully installed:
$ docker run ubuntu ls -l
total 48
drwxr-xr-x 2 root     root       4096 Mar  2 16:20 bin
drwxr-xr-x 5 root     root        360 Mar 18 09:47 dev
drwxr-xr-x   13 root     root          4096 Mar 18 09:47 etc
drwxr-xr-x 2 root     root       4096 Mar  2 16:20 home
drwxr-xr-x 5 root     root       4096 Mar  2 16:20 lib
The ls -l part enabled us to see the listing from Docker.
There you have it! Docker is successfully installed on your server, and you have successfully created your first container. The possibilities are endless from here.
  Docker and containers are a great tool for developers and webmasters! With Docker you can test your applications, visualize your platform, and increase productivity.
Special thanks to Nathan from NFP Hosting for sponsoring this tutorial.  

Top News