mirror of https://github.com/docker/docs.git
error when name already exists in docker run
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
541cb74e84
commit
21ee7e1a13
12
api/api.go
12
api/api.go
|
@ -127,7 +127,10 @@ func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
// POST /containers/create
|
// POST /containers/create
|
||||||
func postContainersCreate(c *context, w http.ResponseWriter, r *http.Request) {
|
func postContainersCreate(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
var config dockerclient.ContainerConfig
|
var (
|
||||||
|
config dockerclient.ContainerConfig
|
||||||
|
name = r.Form.Get("name")
|
||||||
|
)
|
||||||
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&config); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&config); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
@ -139,7 +142,12 @@ func postContainersCreate(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := c.scheduler.CreateContainer(&config, r.Form.Get("name"))
|
if container := c.cluster.Container(name); container != nil {
|
||||||
|
http.Error(w, fmt.Sprintf("Conflict, The name %s is already assigned to %s. You have to delete (or rename) that container to be able to assign %s to a container again.", name, container.Id, name), http.StatusConflict)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
container, err := c.scheduler.CreateContainer(&config, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue