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