func NoOp(c *models.Container, status chan string) { c.Hostname = getHostName() status <- c.Hostname fmt.Println(c.Serialize()) db.SaveContainer(c) time.Sleep(5 * time.Second) c.Status = "READY" db.SaveContainer(c) fmt.Println(c.Serialize()) }
// Start a container func Start(c *models.Container, status chan string) { if !initialized { log.Fatal("Package not initialized. Call .Init() function.") } c.Hostname = getHostName() //Get a random name to use as a hostname c.Url = fmt.Sprintf("http://%s.%s", c.Hostname, c.Domainname) c.StartTime = time.Now() db.SaveContainer(c) //Save startup state in the db status <- c.Hostname //Signal the caller that the record is ready to be read // Create the container containerConfig := &dockerclient.ContainerConfig{ Image: c.Image, Cmd: []string{"/bin/sh", "-c", "ipython notebook --no-browser --port 8888 --ip=* --NotebookApp.allow_origin=*"}, ExposedPorts: map[string]struct{}{ "8888/tcp": {}, }, Hostname: c.Hostname, Domainname: c.Domainname, } containerId, err := docker.CreateContainer(containerConfig, c.Hostname) if err != nil { log.Println(err) } c.ContainerId = containerId // Start the container hostConfig := &dockerclient.HostConfig{ PublishAllPorts: true, } err = docker.StartContainer(containerId, hostConfig) if err != nil { log.Println(err) } ks := kernelStarted(c) if ks { c.Status = "ACTIVE" } else { c.Status = "ERROR" } db.SaveContainer(c) //Save state in the db log.Println("Started container ", c.Serialize()) }