DockerRun performs the specified operation on the given container instance.
(instance string, op int)
| 235 | |
| 236 | // DockerRun performs the specified operation on the given container instance. |
| 237 | func DockerRun(instance string, op int) error { |
| 238 | c := getContainer(instance) |
| 239 | if c.ID == "" { |
| 240 | glog.Fatalf("Unable to find container: %s\n", instance) |
| 241 | return nil |
| 242 | } |
| 243 | |
| 244 | cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) |
| 245 | x.Check(err) |
| 246 | |
| 247 | switch op { |
| 248 | case Start: |
| 249 | if err := cli.ContainerStart(context.Background(), c.ID, container.StartOptions{}); err != nil { |
| 250 | return err |
| 251 | } |
| 252 | case Stop: |
| 253 | dur := 30 |
| 254 | o := container.StopOptions{Timeout: &dur} |
| 255 | return cli.ContainerStop(context.Background(), c.ID, o) |
| 256 | default: |
| 257 | x.Fatalf("Wrong Docker op: %v\n", op) |
| 258 | } |
| 259 | return nil |
| 260 | } |
| 261 | |
| 262 | // MARKED FOR DEPRECATION: DockerCp copies from/to a container. Paths inside a container have the format |
| 263 | // container_name:path. |