Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Add docker run support #8

Open
lxkuz opened this issue Mar 17, 2021 · 1 comment
Open

Add docker run support #8

lxkuz opened this issue Mar 17, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@lxkuz
Copy link
Collaborator

lxkuz commented Mar 17, 2021

This case turned into a more difficult task as Docker API doesn't have "run" from the box.
So we should:

  • Create container with custom command we have from "docker run"
  • Start container
    It may be worth to pull the image if we don't have it as docker run does.
    The solution somehow should look like this:
/ RunContainer works as Docker run command
func (d *Containers) RunContainer(ImageName string, options container.Config) error {
	// _, err := d.cli.ImagePull(d.ctx, ImageName, types.ImagePullOptions{})
	// if err != nil {
	// 	panic(err)
	// }

	resp, err := d.cli.ContainerCreate(d.ctx, &options, nil, nil, nil, "")

	if err != nil {
		return err
	}

	if err := d.StartContainer(resp.ID, types.ContainerStartOptions{}); err != nil {
		return err
	}

	statusCh, errCh := d.cli.ContainerWait(d.ctx, resp.ID, container.WaitConditionNotRunning)
	select {
	case err := <-errCh:
		if err != nil {
			return err
		}
	case <-statusCh:
	}
	return nil
}
@simskij
Copy link

simskij commented Apr 23, 2021

If the config object contains the flag equivalent to --rm we should also remove the container again once the command is done executing.

@simskij simskij added the enhancement New feature or request label Apr 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants