Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Docker in Golang

Docker in Golang

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

jsa :~

April 16, 2014
Tweet

More Decks by jsa :~

Other Decks in Programming

Transcript

  1. Go Docker The most popular Go project and how can

    you do the same. jamie sa  [email protected] Product Manager Speed 3D Inc.
  2. an open source project to pack, ship and run any

    application as a lightweight container
  3. Lightweight Container Linux Containers LXC » Kernel namespaces (ipc, uts,

    mount, pid, network and user) » Chroots (using pivot_root) » Kernel capabilities » Control groups (cgroups)
  4. 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
  5. 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") c.SetVerbosity(lxc.Verbose) 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()) } } }
  6. Most of the appeal for me is not the features

    that Go has, but rather the features that have been intentionally left out.
  7. 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?
  8. 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 } docker.containers.PushBack(container) return container, nil } by Andrea Luzzardi