TODO(vmarmol): Use the Docker remote API. TODO(vmarmol): Refactor a set of "RunCommand" actions. Runs a Docker container in the background. Uses the specified DockerRunArgs and command. e.g.: RunDockerContainer(DockerRunArgs{Image: "busybox"}, "ping", "www.google.com") -> docker run busybox ping
(args DockerRunArgs, cmd ...string)
| 344 | // |
| 345 | // -> docker run busybox ping www.google.com |
| 346 | func (a dockerActions) Run(args DockerRunArgs, cmd ...string) string { |
| 347 | dockerCommand := append(append([]string{"docker", "run", "-d"}, args.Args...), args.Image) |
| 348 | dockerCommand = append(dockerCommand, cmd...) |
| 349 | output, _ := a.fm.Shell().Run("sudo", dockerCommand...) |
| 350 | |
| 351 | // The last line is the container ID. |
| 352 | elements := strings.Fields(output) |
| 353 | containerID := elements[len(elements)-1] |
| 354 | |
| 355 | a.fm.cleanups = append(a.fm.cleanups, func() { |
| 356 | a.fm.Shell().Run("sudo", "docker", "rm", "-f", containerID) |
| 357 | }) |
| 358 | return containerID |
| 359 | } |
| 360 | func (a dockerActions) Version() []string { |
| 361 | dockerCommand := []string{"docker", "version", "-f", "'{{.Server.Version}}'"} |
| 362 | output, _ := a.fm.Shell().Run("sudo", dockerCommand...) |
no test coverage detected