How The Go Programming Language Helps Docker and the Container Ecosystem
This is a chapter from our ebook: The Docker and Container Ecosystem. It’s one of several chapters from the ebook that we will post here over the next several weeks.
To build Docker, developers made the somewhat novel choice of using Google’s relatively new Go programming language.
Given that Docker’s virtualization technology would need to be responsive, a more traditional choice might have been a low-level language such as C. Yet, going with Go turned out to be a wise decision. Go gave the Docker team a simple and powerful language for working with their initial operating system of choice, Linux.
More importantly, it also provides users with an easy path to incorporate Docker’s capabilities into their own environments. Go was built specifically to enable fast development on distributed systems. It allows developers and system administrators to quickly build programs and system tools for cloud computing environments without worrying too much about issues such as dependency management or concurrent programming.
For the developer, Go makes it easy to package pieces of code functionality, and then build applications by assembling these packages. The packages can then be easily reused for other applications as well.
And just as Go helps in development, it also makes life easier during deployment. A Go program can be simple to implement because, once it is compiled, it typically does not require external libraries. A large standard core library provides all the functionality a programmer may need, in most cases. This means an administrator can develop a Go program, copy it over to any remote server with an installed version of Go, and not worry if the program will require additional libraries that the server may not have.
The whole process is made even easier with Docker. There is a special version of the language, available in the Docker Hub, that can package an application within a Docker image during the compilation process, so that it can be immediately deployed. Developers can even build their applications from within the container itself. They don’t even need to have Go on their own computers.
Just as it is easy to install and run Go programs within Docker, it’s very easy to manage Docker containers with Go. Docker provides an API library for interacting with Docker containers using Go.
Go was launched in 2009, and was ready for production use by 2012. Since then, it has been embraced by developers worldwide, particularly in China, where it is most heavily used (though there is discussion about if this difference is as large as the data suggests).
In fact, a surprising number of large enterprises, not the quickest of adopters, have already adopted Go, including Chevron, Verizon, Disney, Walmart, Comcast, General Electric and even Microsoft. IBM has used Go to build a security library for the Internet of Things, as well as for network connectivity software for a swarm of Docker containers.
Many web-scale companies have adopted Go as well. Not only Google, but Facebook and Amazon have gone with Go.
Of course, Google itself provides a hosted Go runtime, as part of its Google App Engine collection of platform services, though other cloud providers, such as Amazon Web Services, support the language as well.
As of latest count, GitHub hosts over 86,600 Go-based software projects, and those are only the open source public projects. No doubt, many private and proprietary software projects are built in Go. And it’s not just a matter of what companies have used Go — many developers report they are planning to use Go in the near future.
In a 2015 StackOverflow developer survey, 19 percent of DevOps developers said they were planning to use Go in the future, representing a predicted increase from the 10 percent currently using Go. As a whole, eight percent of developers plan to use Go in the next year.
In addition to Docker, other container support software has been developed in Go, including the Kubernetes container management software and Hashicorp’s Nomad cluster management software.
It is pretty easy to see that Go will be the core language for the container ecosystem for many years to come. There is a synergy at work here between Docker and Go: if someone sees a bug to fix in Docker, or wishes to improve the software in some way, they use Go, and so they join the league of Go programmers worldwide.
Best of the Old and New
Go’s appeal comes in part from how it combines the best practices from old-school statically-typed programming languages and the newer, dynamically-typed languages often used for building web applications.
Traditional statically-typed languages, such as Java and C++, offer more rigorous controls over data types, which make them safer and faster. Their enforced disciplines, however, make them more difficult to use.
While this dynamic typing can simplify work for the programmer, additional costs sneak out during the runtime in the form of increased cost for testing and debugging. Debugging becomes a lot more of a headache, especially with large programs, if the data types aren’t enforced from the outset. Programs written with dynamic languages also tend be slower than their statically-typed counterparts, especially when scaled up to large workloads.
The beauty of Go is that the language combines the ease of development offered by dynamically-typed languages with the rigor and speed of the statically-typed languages.
As a result, Go programs run more quickly than those written in dynamic languages, which translates directly into lower monthly usage bills for those companies running their web applications in the cloud.
One company that learned this was consultant Iron.io, which built a messaging system for its clients that it later released as a product, called IronWorker. The first version of IronWorker was built in Ruby, which the company found didn’t scale well. After, the program was rewritten in Go, Iron.io was able to cut the number of virtual servers they needed to run IronWorker from 30 to two.
In addition, Go is geared for distributed computing. It has many built-in features to support concurrency, or the ability to run a program across multiple processors. It can execute many low-level system calls, giving it the ability to work directly with the operating system, which speeds up process time.
The language is also friendly to the programmer. Go was built so that the developer can call up the documentation through a single command line. Testing can be executed through a single command as well.
In short, Docker couldn’t have found a better partner than it did in Go.