예제 #1
0
func getImages() []*Image {
	path := fmt.Sprintf("/%s/images/json?all=0", apiVersion)
	c, err := utils.NewDockerClient(dockerURL)
	defer c.Close()
	if err != nil {
		log.Fatalf("Error connecting to Docker: %s", err)
	}
	req, err := http.NewRequest("GET", path, nil)
	if err != nil {
		log.Fatalf("Error requesting images from Docker: %s", err)
	}

	resp, err := c.Do(req)
	if err != nil {
		log.Fatalf("Error requesting images from Docker: %s", err)
	}

	var images []*Image
	if resp.StatusCode == http.StatusOK {
		d := json.NewDecoder(resp.Body)
		if err = d.Decode(&images); err != nil {
			log.Fatalf("Error parsing image JSON: %s", err)
		}
	}
	resp.Body.Close()
	return images
}
예제 #2
0
func inspectContainer(id string) *Container {
	path := fmt.Sprintf("/%s/containers/%s/json?all=1", apiVersion, id)
	c, err := utils.NewDockerClient(dockerURL)
	defer c.Close()
	if err != nil {
		log.Fatalf("Error connecting to Docker: %s", err)
	}
	req, err := http.NewRequest("GET", path, nil)
	if err != nil {
		log.Fatalf("Error inspecting container from Docker: %s", err)
	}
	resp, err := c.Do(req)
	if err != nil {
		log.Fatalf("Error inspecting container from Docker: %s", err)
	}

	var container *Container
	if resp.StatusCode == http.StatusOK {
		d := json.NewDecoder(resp.Body)
		if err = d.Decode(&container); err != nil {
			log.Fatalf("Error parsing container JSON: %s", err)
		}
	}
	resp.Body.Close()
	return container
}