func (e *dockerEngine) StopAndRemoveContainer(containerID string) (err error) {
	err = e.cli.ContainerRemove(e.ctx, containerID, types.ContainerRemoveOptions{Force: true})
	if err != nil {
		logrus.Errorf("Unable to delete container with containerid %s : %s", containerID, err)
		return err
	}
	return nil
}
CreateContainer creates a container
package container
import (
	"bytes"
	"context"
	"fmt"
	"io/ioutil"
	"github.com/docker/docker/api/types"
	"github.com/docker/docker/api/types/container"
	"github.com/docker/docker/api/types/mount"
	"github.com/docker/docker/client"
	"github.com/docker/docker/pkg/stdcopy"
	environmenttypes "github.com/konveyor/move2kube/types/environment"
	"github.com/sirupsen/logrus"
	"github.com/spf13/cast"
)
const (
	testimage = "quay.io/konveyor/hello-world"
)
type dockerEngine struct {
	availableImages map[string]bool
	cli             *client.Client
	ctx             context.Context
}
func newDockerEngine() (*dockerEngine, error) {
	ctx := context.Background()
	cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
	if err != nil {
		logrus.Debugf("Unable to create docker client : %s", err)
		return nil, err
	}
	e := &dockerEngine{
		availableImages: map[string]bool{},
		cli:             cli,
		ctx:             ctx,
	}
	_, _, err = e.RunContainer(testimage, environmenttypes.Command{}, "", "")
	if err != nil {
		logrus.Errorf("Unable to run test container : %s", err)
		return nil, err
	}
	return e, nil
}
func (e *dockerEngine) pullImage(image string) bool {
	if a, ok := e.availableImages[image]; ok {
		return a
	}
	logrus.Infof("Pulling container image %s. This could take a few mins.", image)
	out, err := e.cli.ImagePull(e.ctx, image, types.ImagePullOptions{})
	if err != nil {
		logrus.Debugf("Unable to pull image %s : %s", image, err)
		e.availableImages[image] = false
		return false
	}
	if b, err := ioutil.ReadAll(out); err == nil {
		logrus.Debug(cast.ToString(b))
	}
	e.availableImages[image] = true
	return true
}
func (e *dockerEngine) RunCmdInContainer(containerID string, cmd environmenttypes.Command, workingdir string, env []string) (stdout, stderr string, exitCode int, err error) {
	execConfig := types.ExecConfig{
		AttachStdout: true,
		AttachStderr: true,
		Cmd:          cmd,
		WorkingDir:   workingdir,
		Env:          env,
	}
	cresp, err := e.cli.ContainerExecCreate(e.ctx, containerID, execConfig)
	if err != nil {
		return
	}
	aresp, err := e.cli.ContainerExecAttach(e.ctx, cresp.ID, types.ExecStartCheck{})
	if err != nil {
		return
	}
	defer aresp.Close()
	var outBuf, errBuf bytes.Buffer
	outputDone := make(chan error)
	go func() {
		_, err = stdcopy.StdCopy(&outBuf, &errBuf, aresp.Reader)
		outputDone <- err
	}()
	select {
	case err = <-outputDone:
		if err != nil {
			return
		}
		break
	case <-e.ctx.Done():
		return "", "", 0, e.ctx.Err()
	}
	stdoutbytes, err := ioutil.ReadAll(&outBuf)
	if err != nil {
		return
	}
	stderrbytes, err := ioutil.ReadAll(&errBuf)
	if err != nil {
		return
	}
	res, err := e.cli.ContainerExecInspect(e.ctx, cresp.ID)
	if err != nil {
		return
	}
	exitCode = res.ExitCode
	stdout = string(stdoutbytes)
	stderr = string(stderrbytes)
	return
}
func (e *dockerEngine) InspectImage(image string) (types.ImageInspect, error) {
	inspectOutput, _, err := e.cli.ImageInspectWithRaw(e.ctx, image)
	if err != nil {
		return types.ImageInspect{}, err
	}
	return inspectOutput, nil
}
func (e *dockerEngine) CreateContainer(image string) (containerid string, err error) {
	if !e.pullImage(image) {
		logrus.Debugf("Unable to pull image using docker : %s", image)
		return "", fmt.Errorf("unable to pull image")
	}
	contconfig := &container.Config{
		Image: image,
		Cmd:   []string{"sh", "-c", "tail -f /dev/null"},
	}
	resp, err := e.cli.ContainerCreate(e.ctx, contconfig, nil, nil, nil, "")
	if err != nil {
		logrus.Debugf("Container creation failed with image %s with no volumes", image)
		return "", err
	}
	err = e.cli.ContainerStart(e.ctx, resp.ID, types.ContainerStartOptions{})
	if err != nil {
		logrus.Debugf("Container creation failed with image %s with no volumes", image)
		return "", err
	}
	logrus.Debugf("Container %s created with image %s", resp.ID, image)
	return resp.ID, nil
}