github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/api/handlers/compat/containers_start.go (about) 1 package compat 2 3 import ( 4 "net/http" 5 6 "github.com/sirupsen/logrus" 7 8 "github.com/containers/podman/v2/libpod" 9 "github.com/containers/podman/v2/libpod/define" 10 "github.com/containers/podman/v2/pkg/api/handlers/utils" 11 "github.com/gorilla/schema" 12 ) 13 14 func StartContainer(w http.ResponseWriter, r *http.Request) { 15 decoder := r.Context().Value("decoder").(*schema.Decoder) 16 query := struct { 17 DetachKeys string `schema:"detachKeys"` 18 }{ 19 // Override golang default values for types 20 } 21 if err := decoder.Decode(&query, r.URL.Query()); err != nil { 22 utils.BadRequest(w, "url", r.URL.String(), err) 23 return 24 } 25 if len(query.DetachKeys) > 0 { 26 // TODO - start does not support adding detach keys 27 logrus.Info("the detach keys parameter is not supported on start container") 28 } 29 runtime := r.Context().Value("runtime").(*libpod.Runtime) 30 name := utils.GetName(r) 31 con, err := runtime.LookupContainer(name) 32 if err != nil { 33 utils.ContainerNotFound(w, name, err) 34 return 35 } 36 state, err := con.State() 37 if err != nil { 38 utils.InternalServerError(w, err) 39 return 40 } 41 if state == define.ContainerStateRunning { 42 utils.WriteResponse(w, http.StatusNotModified, "") 43 return 44 } 45 if err := con.Start(r.Context(), len(con.PodID()) > 0); err != nil { 46 utils.InternalServerError(w, err) 47 return 48 } 49 utils.WriteResponse(w, http.StatusNoContent, "") 50 }