Skip to Content
Author's profile photo Former Member

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.

         

Assigned Tags

      17 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks for the comment & sorry for the late reply, I hope it would have worked on your side by now.

      From your comment it looks like you missed the "n" in the golang .

      If you are behind a proxy, then you have to add the proxy config as well in the file.

      Take a look at this.

      internet - How to use a proxy on the command line? - Ask Ubuntu

      Hope everything works out for you...

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Jim, Very useful

      Author's profile photo Former Member
      Former Member

      I Had same issue. are you running it within SAP network or monsoon VM?

      Author's profile photo Mattias Johansson
      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...

      Author's profile photo Former Member
      Former Member
      Blog 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.

      Author's profile photo Mattias Johansson
      Mattias Johansson

      At least there's hope 🙂

      Author's profile photo Mindy Davis
      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...

      Author's profile photo Richard Hirsch
      Richard Hirsch

      I haven't heard that hybris is using Docker but I do know that they are using Cloud Foundry and micro-services.

      Dick

      Author's profile photo Matthias Steiner
      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

      Author's profile photo Shahin Mikailov
      Shahin Mikailov

      Hi Priya,

      Is it possible to install standard SAP ERP in Docker? I mean, multiple standalone installation in one server (using docker)

      Regards,

      Shahin

      Author's profile photo Former Member
      Former Member

      I presented a paper in Cloud Computing Expo on using Docker Containers for IoT and in particular on Gateways. I can share the details if someone is interested

      Author's profile photo Joe Valliparampil
      Joe Valliparampil

      hi Shashank,

      Thank You and please add the link for your presentation.

      _Joe.

      Author's profile photo Former Member
      Former Member
      Author's profile photo Joe Valliparampil
      Joe Valliparampil

      Thanks.

      Author's profile photo Christian Münch
      Christian Münch

      Thanks for the article.

      I would like to mention that the Dockerfile can be optimized.

      A golang application does not need a Ubuntu base image. The binary can run in a scratch container.

      A two step build is better here.

      At the end you need only a compiled binary in the container.