Monthly Archives: May 2015

Getting started with Go Microservices and Docker

What is a microservice

First, you need to learn about the go language. Do these pages in order to learn the bare basics:
https://tour.golang.org/
https://golang.org/doc/install
https://golang.org/doc/code.html

Then you’ll need to learn what docker is, read the understanding docker page:
https://docs.docker.com/introduction/understanding-docker/

And then go install docker and run their hello-world example:
https://docs.docker.com/installation/

Now hopefully you have the basics of go and docker down, so let’s grab an existing microservice and set it up.

On your docker host run:

wget https://github.com/danzel/go-docker-playground/archive/master.tar.gz
tar -zxf master.tar.gz
cd go-docker-playground-master
docker build --tag=danzel/go-docker-playground:1.0 .

This will fetch and then build this docker image which contains a simple web server. Now we can start it up with:

docker create --name=test -P danzel/go-docker-playground:1.0
docker start test

Docker will automatically expose the server on a free port (Thanks to EXPOSE in the Dockerfile and -P in the docker create command line).
To see the port it has chosen:

docker ps

Then you should be able to open it by browsing to http://dockerhostip:port