Implement docker container create with standalone client lib.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 136e8fef64d3dd0e7601ffdad8864b8e1af7c7e5
Component: engine
This commit is contained in:
David Calavera
2015-12-03 14:14:36 -05:00
parent 4c16000788
commit f0680b3c8f
3 changed files with 92 additions and 27 deletions

View File

@ -0,0 +1,43 @@
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
}