1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/api/client/lib/container_create.go
David Calavera 136e8fef64 Implement docker container create with standalone client lib.
Signed-off-by: David Calavera <david.calavera@gmail.com>
2015-12-09 12:04:53 -05:00

43 lines
1.1 KiB
Go

package lib
import (
"encoding/json"
"net/url"
"strings"
"github.com/docker/docker/api/types"
"github.com/docker/docker/runconfig"
)
// 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(config *runconfig.ContainerConfigWrapper, containerName string) (types.ContainerCreateResponse, error) {
var (
query url.Values
response types.ContainerCreateResponse
)
if containerName != "" {
query.Set("name", containerName)
}
serverResp, err := cli.POST("/containers/create", query, config, nil)
if err != nil {
if serverResp != nil && serverResp.statusCode == 404 && strings.Contains(err.Error(), config.Image) {
return response, imageNotFoundError{config.Image}
}
return response, err
}
if serverResp.statusCode == 404 && strings.Contains(err.Error(), config.Image) {
}
if err != nil {
return response, err
}
if err := json.NewDecoder(serverResp.body).Decode(&response); err != nil {
return response, err
}
return response, nil
}