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 d9a62c5f2b Lowercase http method functions.
Signed-off-by: David Calavera <david.calavera@gmail.com>
2015-12-09 12:04:59 -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 response types.ContainerCreateResponse
query := url.Values{}
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) {
return response, imageNotFoundError{config.Image}
}
if err != nil {
return response, err
}
defer ensureReaderClosed(serverResp)
if err := json.NewDecoder(serverResp.body).Decode(&response); err != nil {
return response, err
}
return response, nil
}