Example #1
0
// commitContainerToImage commits the container with the given containerID
// that is based on the given img into a new image. The given repo should also
// contain the namespace. Returns the id of the created image.
func commitContainerToImage(img, containerID, repo, tag, comment, author string) (string, error) {
	client := getDockerClient()

	// First of all, we inspect the parent image and fetch the values for the
	// entrypoint and the cmd. We do this to preserve them on the committed
	// image. See issue: https://github.com/SUSE/zypper-docker/issues/75.
	info, _, err := client.ImageInspectWithRaw(img, false)
	if err != nil {
		return "", fmt.Errorf("could not inspect image '%s': %v", img, err)
	}
	changes := []string{
		"ENTRYPOINT " + joinAsArray(info.Config.Entrypoint.Slice(), false),
		"CMD " + joinAsArray(info.Config.Cmd.Slice(), true),
	}

	// And we commit into the new image.
	resp, err := client.ContainerCommit(types.ContainerCommitOptions{
		ContainerID:    containerID,
		RepositoryName: repo,
		Tag:            tag,
		Comment:        comment,
		Author:         author,
		Changes:        changes,
		Config:         &container.Config{},
	})
	return resp.ID, err
}
Example #2
0
func (s *Service) imageExists() error {
	client := s.context.ClientFactory.Create(s)

	_, _, err := client.ImageInspectWithRaw(context.Background(), s.imageName(), false)
	return err
}