Go Docker!

[fit]Go Docker

The most popular Go project and how you can do the same.

jamie sa 撒景賢
Product Manager
Speed 3D Inc.

^ ex founder of Waveface
mostly Cocoa in past 3 years

[fit]Docker is

^ anyone heard of it, anyone try in before

A project started by Solomon Hykes


^ First some background. dotCloud is in a very busy space, the PaaS landscape is rapidly converging on a few ecosystems of note. There is Heroku, the

Almost got sold that time.

an open source project to pack, ship and run any application as a lightweight container

Open Source

Highly active since very begining

Lightweight Container

Linux Containers LXC

  • Kernel namespaces (ipc, uts, mount, pid, network and user)
  • Chroots (using pivot_root)
  • Kernel capabilities
  • Control groups (cgroups)

^ The goal of LXC is to create an environment as close as possible as a standard Linux installation but without the need for a separate kernel.

PID namespaces in the 2.6.24 kernel

struct upid {
    int nr;                         /* moved from struct pid */
    struct pid_namespace *ns;      /* the namespace this value is visible in */
    struct hlist_node pid_chain;  /* moved from struct pid */

struct pid {
    atomic_t count;
    struct hlist_head tasks[PIDTYPE_MAX];
    struct rcu_head rcu;
    int level;                /* the number of upids */
    struct upid numbers[0];

November 19, 2007

^ Thinking in chroot or jail


Go Bindings for LXC

in lxc.c

pid_t go_lxc_init_pid(struct lxc_container *c) {
    return c->init_pid(c);

Creating an lxc container in Go

func main() {
    c, err := lxc.NewContainer(name, lxcpath)
    if err != nil {
        log.Fatalf("ERROR: %s\n", err.Error())
    defer lxc.PutContainer(c)

    log.Printf("Creating container...\n")

    if os.Geteuid() != 0 {
        if err := c.CreateAsUser(distro, release, arch); err != nil {
            log.Printf("ERROR: %s\n", err.Error())
    } else {
        if err := c.Create(template, "-a", arch, "-r", release); err != nil {
            log.Printf("ERROR: %s\n", err.Error())

Before I try

Most of the appeal for me is not the features that Go has, but rather the features that have been intentionally left out.

^ read effetive go if you haven't.

After that certain date.

Why Go?

  1. Static compilation
  2. Netural
  3. It has what we need
  4. Full development environment
  5. Multi-arch build

Jérôme Petazzoni, Docker and Go: why did we decide to write Docker in Go?

^ easy to install, deploy
^ not C++, Python, Ruby, Java
^ asynchronous primitives,
^ doc, get ,fmt, test run
^ _linux, _darwin

Jan 19, 2013, Initial commit

func (docker *Docker) Create(name string, command string, 
    args []string, layers []string, config *Config) (*Container, error) {

    if docker.Exists(name) {
        return nil, fmt.Errorf("Container %v already exists", name)
    root := path.Join(docker.repository, name)
    container, err := createContainer(name, root, command, args, layers, config)
    if err != nil {
        return nil, err
    return container, nil

by Andrea Luzzardi

^ A googler now


What kind of web serivce do you use?

  • AWS
  • [.*]Azure
  • Linode

^ The prefix changes from time to time

One More thing

Critical Mass

April 19, 2014, Saturday 4PM