podman

Форк
0
42 строки · 1.1 Кб
1
package docker
2

3
import (
4
	"context"
5
	"errors"
6
	"fmt"
7
	"net/http"
8
)
9

10
// StopContainer stops a container, killing it after the given timeout (in
11
// seconds).
12
//
13
// See https://goo.gl/R9dZcV for more details.
14
func (c *Client) StopContainer(id string, timeout uint) error {
15
	return c.stopContainer(id, timeout, doOptions{})
16
}
17

18
// StopContainerWithContext stops a container, killing it after the given
19
// timeout (in seconds). The context can be used to cancel the stop
20
// container request.
21
//
22
// See https://goo.gl/R9dZcV for more details.
23
func (c *Client) StopContainerWithContext(id string, timeout uint, ctx context.Context) error {
24
	return c.stopContainer(id, timeout, doOptions{context: ctx})
25
}
26

27
func (c *Client) stopContainer(id string, timeout uint, opts doOptions) error {
28
	path := fmt.Sprintf("/containers/%s/stop?t=%d", id, timeout)
29
	resp, err := c.do(http.MethodPost, path, opts)
30
	if err != nil {
31
		var e *Error
32
		if errors.As(err, &e) && e.Status == http.StatusNotFound {
33
			return &NoSuchContainer{ID: id}
34
		}
35
		return err
36
	}
37
	defer resp.Body.Close()
38
	if resp.StatusCode == http.StatusNotModified {
39
		return &ContainerNotRunning{ID: id}
40
	}
41
	return nil
42
}
43

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

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

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

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