mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
e98e4a7111
Signed-off-by: Victor Vieux <vieux@docker.com> update cobra and use Tags Signed-off-by: Victor Vieux <vieux@docker.com> allow client to talk to an older server Signed-off-by: Victor Vieux <vieux@docker.com>
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package client
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
"github.com/docker/docker/api/types/network"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
type configWrapper struct {
|
|
*container.Config
|
|
HostConfig *container.HostConfig
|
|
NetworkingConfig *network.NetworkingConfig
|
|
}
|
|
|
|
// ContainerCreate creates a new container based in the given configuration.
|
|
// It can be associated with a name, but it's not mandatory.
|
|
func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) {
|
|
var response container.ContainerCreateCreatedBody
|
|
|
|
if err := cli.NewVersionError("1.25", "stop timeout"); config != nil && config.StopTimeout != nil && err != nil {
|
|
return response, err
|
|
}
|
|
|
|
query := url.Values{}
|
|
if containerName != "" {
|
|
query.Set("name", containerName)
|
|
}
|
|
|
|
body := configWrapper{
|
|
Config: config,
|
|
HostConfig: hostConfig,
|
|
NetworkingConfig: networkingConfig,
|
|
}
|
|
|
|
serverResp, err := cli.post(ctx, "/containers/create", query, body, nil)
|
|
if err != nil {
|
|
if serverResp.statusCode == 404 && strings.Contains(err.Error(), "No such image") {
|
|
return response, imageNotFoundError{config.Image}
|
|
}
|
|
return response, err
|
|
}
|
|
|
|
err = json.NewDecoder(serverResp.body).Decode(&response)
|
|
ensureReaderClosed(serverResp)
|
|
return response, err
|
|
}
|