forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer_create.go
34 lines (26 loc) · 868 Bytes
/
container_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package client
import (
"context"
"net/url"
"github.com/alibaba/pouch/apis/types"
)
// ContainerCreate creates a new container based in the given configuration.
func (client *APIClient) ContainerCreate(ctx context.Context, config types.ContainerConfig, hostConfig *types.HostConfig, networkingConfig *types.NetworkingConfig, containerName string) (*types.ContainerCreateResp, error) {
createConfig := types.ContainerCreateConfig{
ContainerConfig: config,
HostConfig: hostConfig,
NetworkingConfig: networkingConfig,
}
q := url.Values{}
if containerName != "" {
q.Set("name", containerName)
}
resp, err := client.post(ctx, "/containers/create", q, createConfig, nil)
if err != nil {
return nil, err
}
container := &types.ContainerCreateResp{}
err = decodeBody(container, resp.Body)
ensureCloseReader(resp)
return container, err
}