podman
57 строк · 1.9 Кб
1package docker2
3import (4"context"5"errors"6"net/http"7)
8
9// StartContainer starts a container, returning an error in case of failure.
10//
11// Passing the HostConfig to this method has been deprecated in Docker API 1.22
12// (Docker Engine 1.10.x) and totally removed in Docker API 1.24 (Docker Engine
13// 1.12.x). The client will ignore the parameter when communicating with Docker
14// API 1.24 or greater.
15//
16// See https://goo.gl/fbOSZy for more details.
17func (c *Client) StartContainer(id string, hostConfig *HostConfig) error {18return c.startContainer(id, hostConfig, doOptions{})19}
20
21// StartContainerWithContext starts a container, returning an error in case of
22// failure. The context can be used to cancel the outstanding start container
23// request.
24//
25// Passing the HostConfig to this method has been deprecated in Docker API 1.22
26// (Docker Engine 1.10.x) and totally removed in Docker API 1.24 (Docker Engine
27// 1.12.x). The client will ignore the parameter when communicating with Docker
28// API 1.24 or greater.
29//
30// See https://goo.gl/fbOSZy for more details.
31func (c *Client) StartContainerWithContext(id string, hostConfig *HostConfig, ctx context.Context) error {32return c.startContainer(id, hostConfig, doOptions{context: ctx})33}
34
35func (c *Client) startContainer(id string, hostConfig *HostConfig, opts doOptions) error {36path := "/containers/" + id + "/start"37if c.serverAPIVersion == nil {38c.checkAPIVersion()39}40if c.serverAPIVersion != nil && c.serverAPIVersion.LessThan(apiVersion124) {41opts.data = hostConfig42opts.forceJSON = true43}44resp, err := c.do(http.MethodPost, path, opts)45if err != nil {46var e *Error47if errors.As(err, &e) && e.Status == http.StatusNotFound {48return &NoSuchContainer{ID: id, Err: err}49}50return err51}52defer resp.Body.Close()53if resp.StatusCode == http.StatusNotModified {54return &ContainerAlreadyRunning{ID: id}55}56return nil57}
58