Exemple #1
0
func stopAndDeleteDevice(deviceSn string, docker *dc.DockerClient) error {
	container := "device" + deviceSn
	err := docker.KillContainer(container)
	if err != nil {
		return err
	}

	err = docker.RemoveContainer(container)
	return nil
}
func removeContainers(client *dockerclient.DockerClient, containers []*dockerclient.ContainerInfo) error {
	for _, container := range containers {
		log.Printf("rm %s (%s)", container.Id, container.Name)
		if !*dry {
			if err := client.RemoveContainer(container.Id, false, false); err != nil {
				debug("Couldn't remove container: %s", err)
			}
		}
	}
	return nil
}
Exemple #3
0
func (job *Job) Exec(docker *dockerclient.DockerClient,
	w io.Writer) error {

	containerConfig := &dockerclient.ContainerConfig{
		Image:        job.Image,
		Cmd:          []string{"/bin/bash", "-c", job.Cmd},
		AttachStdout: true,
		AttachStderr: true,
	}
	cid, err := docker.CreateContainer(containerConfig,
		fmt.Sprintf("spot-trader-job-%d", job.ID))
	if err != nil {
		return fmt.Errorf("creating container: %v", err)
	}
	defer func() {
		if err = docker.RemoveContainer(cid, false, false); err != nil {
			log.Printf("error removing container: %v", err)
		}
	}()
	options := &dockerclient.AttachOptions{Stdout: true, Stderr: true, Stream: true}
	stdout, err := docker.AttachContainer(cid, options)
	if err != nil {
		return fmt.Errorf("attaching: %v", err)
	}
	err = docker.StartContainer(cid, nil)
	if err != nil {
		return fmt.Errorf("starting container: %v", err)
	}
	done := make(chan struct{})
	go func() {
		err := copyDockerOut(w, w, stdout)
		if err != nil {
			log.Println(err)
		}
		stdout.Close()
		close(done)
	}()
	<-done
	err = docker.StopContainer(cid, 5)
	if err != nil {
		log.Printf("error stopping container: %v",
			err)
	}
	return nil
}
func supprDocker(docker *dockerclient.DockerClient, dockerName string) {

	var searchDockerName string = "{\"name\":[\"" + dockerName + "\"]}"
	//l4g.Info("%v\n", searchDockerName)
	// Get only running containers
	containers, err := docker.ListContainers(true, true, searchDockerName)
	if err != nil {
		log.Fatal(err)
	}
	for _, c := range containers {
		l4g.Info(c.Id, c.Names)

		if err := docker.RemoveContainer(c.Id, true, false); err != nil {
			//l4g.Info("cannot stop container: %s", err)
			var RS string = fmt.Sprintf("cannot stop container: %s", err)
			l4g.Info(RS)
			writeSDLstr(RS)

		}
	}
}
Exemple #5
0
func stopVaultOnShutdown(containerId string, docker *dockerclient.DockerClient) {
	log.Info("... stopping container ", containerId, "...")
	docker.StopContainer(containerId, 5)
	docker.RemoveContainer(containerId, true, false)
}