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.

         

To report this post you need to login first.

16 Comments

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

  1. Marco TERRINONI

    Hi,

    I’m following your guide, but I’m having a problem while retrieving the golang package and the error is “E: Unable to locate package golag”.

    I’m quite sure that it’s due to SAP proxy, indeed if I include the line “RUN apt-get update” in Dockerfile, when building, I see a list of “Failed to fetch http…” and “Could not resolve ‘archive.ubuntu.com'”.
    I also tried to follow the suggestions from here http://stackoverflow.com/questions/22179301/how-do-you-run-apt-get-in-a-dockerfile-behind-a-proxy
    But nothing changes…
    Do you have any suggestion to solve this problem?

    Thanks!

    MT

    (0) 
    1. James Prins

      I had the same problem, probably because i wasn’t using the exact docker configuration as the author.  I was able to make it work by adding a line to the Dockerfile (shown below), which runs apt-get -y update first.  That allowed the next apt-get to find golang.

      FROM ubuntu

      #I added this line below

      RUN apt-get -y update

      RUN apt-get -y install golang

      ADD server.go /src/server.go

      EXPOSE 9090

      CMD [“go”,”run”,”/src/server.go”]

      I also had to update server.go to add missing line “package main” as shown below:

      server.go contents below

      #added this line below

      package main

      import (

          “io”

          “net/http”

          “log”

          “fmt”

      )

      Hope that helps someone!

      – Jim

      (0) 
  2. Mattias Johansson

    I have also been using Docker (in conjunction with nodejs), but am wondering how we could benefit from this in the SAP World?

    It would be great to be able to run docker containers in the Hana Cloud…

    (0) 
    1. Priya Ranjan Post author

      I think there were some slides which showed that SAP internally is looking at Docker.

      Whether it will be leveraged at a large scale in SAP Cloud remains to be seen in the future.

      (0) 
  3. Mindy Davis

    Great article that helps articulate Docker’s value proposition — thank you.

    I’ve heard that SAP IS running Docker containers in the cloud; specifically, to run Hybris in the cloud.  Do you know if this is true?  And if so, any slides you can share to show the supported business processes?  Perhaps it’s premature, but worth the ask…

    (0) 
    1. Matthias Steiner

      I’ve heard that SAP IS running Docker containers in the cloud; specifically, to run Hybris in the cloud.  Do you know if this is true? 

      Hi Mindy,

      no, that’s not true. However, we do have plans to support Docker in HCP as outlined in our roadmap (p. 20).

      Best regards,

      matthias

      (0) 

Leave a Reply