podman
41 строка · 1.0 Кб
1package docker
2
3import (
4"context"
5"errors"
6"net/http"
7)
8
9// RemoveContainerOptions encapsulates options to remove a container.
10//
11// See https://goo.gl/hL5IPC for more details.
12type RemoveContainerOptions struct {
13// The ID of the container.
14ID string `qs:"-"`
15
16// A flag that indicates whether Docker should remove the volumes
17// associated to the container.
18RemoveVolumes bool `qs:"v"`
19
20// A flag that indicates whether Docker should remove the container
21// even if it is currently running.
22Force bool
23Context context.Context
24}
25
26// RemoveContainer removes a container, returning an error in case of failure.
27//
28// See https://goo.gl/hL5IPC for more details.
29func (c *Client) RemoveContainer(opts RemoveContainerOptions) error {
30path := "/containers/" + opts.ID + "?" + queryString(opts)
31resp, err := c.do(http.MethodDelete, path, doOptions{context: opts.Context})
32if err != nil {
33var e *Error
34if errors.As(err, &e) && e.Status == http.StatusNotFound {
35return &NoSuchContainer{ID: opts.ID}
36}
37return err
38}
39resp.Body.Close()
40return nil
41}
42