Skip to Content

Docker – Containers In The Cloud

What is Docker ?

Docker is an opensource virtualization technology which packages your compute environment into a container, which can then be started, stopped, saved and shipped to other clouds/datacenter in a transparent way. We all are very familiar with technologies like VMWare or Virtualbox where we can get an image of the system and run it anywhere we have the player for them installed. Well Docker is similar except that it is native ( with a very thin wrapper ) to Linux kernel.

What problem does Docker solves ?

Imagine you could build a service in your laptop, package it as a container and ship it to be deployed in your linux datacenter or cloud or someone else laptop.

Imagine you could also version your service package and only ship the bits which are different, saving huge amount of bandwidth. You could also start the container on demand basis, assign memory and CPU to it, get the work done and shut it down. In short Docker standardizes your virtual appliance that can then be transported anywhere, where Docker is supported and could be started. Following are few advantages.

  • Complete Isolation of applications and services – Each container runs in its own sandbox and is completely isolated from other containers.
  • Security – Due to isolation of containers, security impact on one container does not impact other containers. Fine grained security possible.
  • Testable, Reproducible environments – You can re-create complete config environments in seconds, without going through the pain of installing each bits everytime.
  • Modification to Containers are easy and versioned – Easily modify containers, only the changed bits are shipped, saving the bandwidth.
  • Container Repository – You can have a container repository, pick and choose for your recipe, build entire cluster, distributed landscape in seconds, test and destroy.

What’s the biggest  problem that Docker solves ?

Imagine that you have built an application. It’s a general web based application which has a database, a programming language, a server on your local laptop.

Now you want to deploy this application in your data center, what do you do ? you re-install all the dependency on your data center, configure them and start behind a load balancer. But before that in an enterprise environment you have to do the same in Dev and QA.

Now suppose in production you have two data centers, now you to install, configure and deploy all of the same in all the data centers.

After some time the management decides that your application should actually run in the cloud and ask you to now provision your application inside a cloud provider. You learn, register, start, install, configure and provision your application again.

In all the above, you would face huge challenges just in installing and configuring things. Let alone running and fixing production bugs. Instead if you had Dockerized your application, then you can ship the container to your data center, VMs or Cloud and fine tuned the resource allotment with just a few commands.

No need to install and reconfigure your application dependency from scratch. The container is standard and can run anywhere. More CPU and Memory and other resources can be allotted. If you change something then only the different bits are uploaded to your data center or cloud.  This is the exact transport model of all shipping corporation in the world. The shipping container abstracts as to what is being shipped in a standard package, which goes from source to target via various transportation ,echanism to it’s destination.

By this abstraction you can save enormous amount of time in developer operations and focus more on business of application development.

Quick Intro to Docker

Install latest Ubuntu x64 ( currently 14 LTS ) in your VMWare or Virtualbox, boot it up and issue following commands into the terminal.

  • Ensure that you are using latest kernel ( this is important otherwise starting of Docker fails ) by following cmd – uname -r

         

        In case you are not the newest version of the kernel then upgrade your system running “Software Updater”

  • Install Docker with following commands

$ sudo apt-get update

$ sudo apt-get install docker.io

$ sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker

$ sudo sed -i ‘$acomplete -F _docker docker’ /etc/bash_completion.d/docker.io

        At the end you should have docker installed on your system

  • Issue following command to start the docker container – sudo docker -d &

         

  • Issue following command to see all running Dockers – sudo docker p

           


Now we would “Dockerize” ( ie containerize ) a simple hello world server written in Golang ( the programming language in which Docker itself is written in )


Step 1. Create a Dockerfile in the current directory which looks like this 

                 You can use commands like –  gedit Dockerfile  and paste following content.


FROM ubuntu
RUN apt-get -y install golang
ADD server.go /src/server.go
ADD . /src
EXPOSE 9090
CMD ["go","run","/src/server.go"]


Step 2. Create a server.go file which looks like this

                 Again you can use command – gedit server.go and paste the following content.



import (
    "io"
    "net/http"
    "log"
    "fmt"
)
// hello world, the web server
func HelloServer(w http.ResponseWriter, req *http.Request) {
    io.WriteString(w, "hello, world!\n")
}
func main() {
    fmt.Println("Starting server")
    http.HandleFunc("/hello", HelloServer)
    err := http.ListenAndServe(":9090", nil)
    if err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}



Step 3. Build the container with following command – sudo docker build -t godock .   # there is dot in the end

         

Step 4. Start and run your container with following command – sudo docker run –rm -P -p 9090:9090 –name trial godock &

       

Step 5 : Go to URL http://localhost:9090/hello in your browser and you will see the result.

         

16 Comments
You must be Logged on to comment or reply to a post.