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.
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.
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.
Install latest Ubuntu x64 ( currently 14 LTS ) in your VMWare or Virtualbox, boot it up and issue following commands into the terminal.
In case you are not the newest version of the kernel then upgrade your system running "Software Updater"
$ 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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |