First Docker Image & Container (Ubuntu 14.04+ golang):-
I wanted to share some basic Docker information and help everyone get setup with a simple Docker running Ubuntu 14.04 with golang. I have completed the Docker POC with Go language. Now Go application is running successfully in docker on top of Ubuntu 14.04. The biggest challenge what I faced was "Dockerize" ( ie containerize) the server. Because it requires to install and configure my application dependency from scratch, so took for me lot of time first. The second time I had reused my Dockerized file in different systems. Just using a few commands I ran my application within a minutes. Please follow the below steps to understand and to get hands- dirty on docker. Get back to me in case of more details required.
Prerequisites:-
- Reserve latest Ubuntu 14.04 x64 from monsoon https://monsoon.mo.sap.corp/ [ select type 4 CPUs, 6 GB(medium_4_6)] 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
$ apt-get update
$ apt-get install docker.io
$ ln -sf /usr/bin/docker.io /usr/local/bin/docker
$ 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 - docker -d &
- Issue following command to see all running Dockers - docker ps or docker ps –a
Go language Example:-
Step 1. Now we would "Dockerize" ( ie containerize ) a simple hello world server written in Golang ( the programming language in which Docker itself is written in ). Create a Dockerfile and server.go file and keep it in the /home/i307955 and Dockerfile looks like this[I have created already, Please use the below].
Docker file:-
FROM ubuntu
RUN http_proxy=http://proxy.wdf.sap.corp:8080 apt-get update
RUN http_proxy=http://proxy.wdf.sap.corp:8080 apt-get -y install wget
RUN http_proxy=http://proxy.wdf.sap.corp:8080 wget http://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz
RUN tar -C /usr/local -xzf go1.4.2.linux-amd64.tar.gz
ADD server.go /src/server.go
EXPOSE 9090
CMD ["/usr/local/go/bin/go","run","/src/server.go"]
server.go
package main
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 2. Build the container with following command - docker build -t godock . # there is dot in the end
Step 3. Start and run your container with following command - docker run --rm -P -p 9090:9090 --name trial godock
Step 4 : Go to URL http://localhost:9090/hello in your browser and you will see the result
BR,Gowrisankar