From 6acd265306370ab5cfeaf2843bd359fe13216d92 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 18 Mar 2021 12:45:09 -0400 Subject: Add --requires flag to podman run/create 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 --- cmd/podman/common/create.go | 8 ++++++++ cmd/podman/common/create_opts.go | 1 + cmd/podman/common/specgen.go | 2 ++ 3 files changed, 11 insertions(+) (limited to 'cmd/podman/common') diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index d1170710b..2169cdc9f 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -576,6 +576,14 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) { `If a container with the same name exists, replace it`, ) + requiresFlagName := "requires" + createFlags.StringSliceVar( + &cf.Requires, + requiresFlagName, []string{}, + "Add one or more requirement containers that must be started before this container will start", + ) + _ = cmd.RegisterFlagCompletionFunc(requiresFlagName, AutocompleteContainers) + restartFlagName := "restart" createFlags.StringVar( &cf.Restart, diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go index a296ef4f1..e14918fe1 100644 --- a/cmd/podman/common/create_opts.go +++ b/cmd/podman/common/create_opts.go @@ -93,6 +93,7 @@ type ContainerCLIOpts struct { ReadOnlyTmpFS bool Restart string Replace bool + Requires []string Rm bool RootFS bool Secrets []string diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go index d1b67d963..363a8f5f9 100644 --- a/cmd/podman/common/specgen.go +++ b/cmd/podman/common/specgen.go @@ -486,6 +486,8 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string s.ReadOnlyFilesystem = c.ReadOnly s.ConmonPidFile = c.ConmonPIDFile + s.DependencyContainers = c.Requires + // TODO // outside of specgen and oci though // defaults to true, check spec/storage -- cgit v1.2.3-54-g00ecf