mirror of
https://github.com/containers/podman.git
synced 2025-05-19 08:07:10 +08:00

Podman has, for a long time, had an internal concept of dependency management, used mainly to ensure that pod infra containers are started before any other container in the pod. We also have the ability to recursively start these dependencies, which we use to ensure that `podman start` on a container in a pod will not fail because the infra container is stopped. We have not, however, exposed these via the command line until now. Add a `--requires` flag to `podman run` and `podman create` to allow users to manually specify dependency containers. These containers must be running before the container will start. Also, make recursive starting with `podman start` default so we can start these containers and their dependencies easily. Fixes #9250 Signed-off-by: Matthew Heon <matthew.heon@pm.me>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package compat
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/containers/podman/v3/libpod"
|
|
"github.com/containers/podman/v3/libpod/define"
|
|
"github.com/containers/podman/v3/pkg/api/handlers/utils"
|
|
"github.com/gorilla/schema"
|
|
)
|
|
|
|
func StartContainer(w http.ResponseWriter, r *http.Request) {
|
|
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
|
query := struct {
|
|
DetachKeys string `schema:"detachKeys"`
|
|
}{
|
|
// Override golang default values for types
|
|
}
|
|
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
|
utils.BadRequest(w, "url", r.URL.String(), err)
|
|
return
|
|
}
|
|
if len(query.DetachKeys) > 0 {
|
|
// TODO - start does not support adding detach keys
|
|
logrus.Info("the detach keys parameter is not supported on start container")
|
|
}
|
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
|
name := utils.GetName(r)
|
|
con, err := runtime.LookupContainer(name)
|
|
if err != nil {
|
|
utils.ContainerNotFound(w, name, err)
|
|
return
|
|
}
|
|
state, err := con.State()
|
|
if err != nil {
|
|
utils.InternalServerError(w, err)
|
|
return
|
|
}
|
|
if state == define.ContainerStateRunning {
|
|
utils.WriteResponse(w, http.StatusNotModified, nil)
|
|
return
|
|
}
|
|
if err := con.Start(r.Context(), true); err != nil {
|
|
utils.InternalServerError(w, err)
|
|
return
|
|
}
|
|
utils.WriteResponse(w, http.StatusNoContent, nil)
|
|
}
|