podman

Форк
0
57 строк · 1.9 Кб
1
package docker
2

3
import (
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.
17
func (c *Client) StartContainer(id string, hostConfig *HostConfig) error {
18
	return 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.
31
func (c *Client) StartContainerWithContext(id string, hostConfig *HostConfig, ctx context.Context) error {
32
	return c.startContainer(id, hostConfig, doOptions{context: ctx})
33
}
34

35
func (c *Client) startContainer(id string, hostConfig *HostConfig, opts doOptions) error {
36
	path := "/containers/" + id + "/start"
37
	if c.serverAPIVersion == nil {
38
		c.checkAPIVersion()
39
	}
40
	if c.serverAPIVersion != nil && c.serverAPIVersion.LessThan(apiVersion124) {
41
		opts.data = hostConfig
42
		opts.forceJSON = true
43
	}
44
	resp, err := c.do(http.MethodPost, path, opts)
45
	if err != nil {
46
		var e *Error
47
		if errors.As(err, &e) && e.Status == http.StatusNotFound {
48
			return &NoSuchContainer{ID: id, Err: err}
49
		}
50
		return err
51
	}
52
	defer resp.Body.Close()
53
	if resp.StatusCode == http.StatusNotModified {
54
		return &ContainerAlreadyRunning{ID: id}
55
	}
56
	return nil
57
}
58

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.