Skip to content

Instantly share code, notes, and snippets.

@odewahn
Created March 9, 2016 20:19
Show Gist options
  • Save odewahn/8e947bd03df879e21de1 to your computer and use it in GitHub Desktop.
Save odewahn/8e947bd03df879e21de1 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/rand"
"fmt"
"log"
"github.com/fsouza/go-dockerclient"
)
func main() {
endpoint := "tcp://104.130.0.92:2376"
path := "/Users/odewahn/.carina/clusters/aodewahn/carina1/"
//endpoint := "tcp://192.168.99.100:2376"
//path := "/Users/odewahn/.docker/machine/machines/launchbot"
ca := fmt.Sprintf("%s/ca.pem", path)
cert := fmt.Sprintf("%s/cert.pem", path)
key := fmt.Sprintf("%s/key.pem", path)
client, _ := docker.NewTLSClient(endpoint, cert, key, ca)
// use client
containerConfig := docker.Config{
Image: "jupyter/notebook",
}
hostConfig := docker.HostConfig{
PublishAllPorts: true,
}
options := docker.CreateContainerOptions{
Name: getHostName(),
Config: &containerConfig,
}
c, err := client.CreateContainer(options)
if err != nil {
log.Fatal(err)
}
err = client.StartContainer(c.ID, &hostConfig)
if err != nil {
log.Fatal(err)
}
}
// This just makes up a random hostname
// From https://www.socketloop.com/tutorials/golang-how-to-generate-random-string
func getHostName() string {
dictionary := "0123456789abcdefghijklmnopqrstuvwxyz"
var bytes = make([]byte, 12)
rand.Read(bytes)
for k, v := range bytes {
bytes[k] = dictionary[v%byte(len(dictionary))]
}
return string(bytes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment