mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-10-30 12:55:22 +00:00
Generated largely from the specified config; small parts taken from `docker image inspect`, such as the command line. Renamed some of the yaml keys to match the OCI spec rather than Docker Compose as we decided they are more readable, no more underscores. Add some extra functionality - tmpfs specification - fully general mount specification - no new privileges can be specified now For nostalgic reasons, using engine-api to talk to the docker cli as we only need an old API version, and it is nice and easy to vendor... Signed-off-by: Justin Cormack <justin.cormack@docker.com>
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package client
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/docker/engine-api/types"
|
|
"github.com/docker/engine-api/types/container"
|
|
"github.com/docker/engine-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) (types.ContainerCreateResponse, error) {
|
|
var response types.ContainerCreateResponse
|
|
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 != nil && 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
|
|
}
|