Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ env:
####
#### Cache-image names to test with
###
FEDORA_CACHE_IMAGE_NAME: "fedora-30-libpod-5925244995371008"
PRIOR_FEDORA_CACHE_IMAGE_NAME: "fedora-29-libpod-5925244995371008"
UBUNTU_CACHE_IMAGE_NAME: "ubuntu-18-libpod-5925244995371008"
FEDORA_CACHE_IMAGE_NAME: "fedora-30-libpod-5479475851034624"
PRIOR_FEDORA_CACHE_IMAGE_NAME: "fedora-29-libpod-5479475851034624"
UBUNTU_CACHE_IMAGE_NAME: "ubuntu-18-libpod-5479475851034624"

####
#### Variables for composing new cache-images (used in PR testing) from
Expand Down
26 changes: 26 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in

[func Diff(name: string) DiffInfo](#Diff)

[func ExecContainer(opts: ExecOpts) ](#ExecContainer)

[func ExportContainer(name: string, path: string) string](#ExportContainer)

[func ExportImage(name: string, destination: string, compress: bool, tags: []string) string](#ExportImage)
Expand Down Expand Up @@ -203,6 +205,8 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in

[type Event](#Event)

[type ExecOpts](#ExecOpts)

[type Image](#Image)

[type ImageHistory](#ImageHistory)
Expand Down Expand Up @@ -439,6 +443,11 @@ $ varlink call -m unix:/run/podman/io.podman/io.podman.DeleteUnusedImages

method Diff(name: [string](https://godoc.org/builtin#string)) [DiffInfo](#DiffInfo)</div>
Diff returns a diff between libpod objects
### <a name="ExecContainer"></a>func ExecContainer
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">

method ExecContainer(opts: [ExecOpts](#ExecOpts)) </div>
ExecContainer executes a command in the given container.
### <a name="ExportContainer"></a>func ExportContainer
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">

Expand Down Expand Up @@ -1565,6 +1574,23 @@ status [string](https://godoc.org/builtin#string)
time [string](https://godoc.org/builtin#string)

type [string](https://godoc.org/builtin#string)
### <a name="ExecOpts"></a>type ExecOpts



name [string](https://godoc.org/builtin#string)

tty [bool](https://godoc.org/builtin#bool)

privileged [bool](https://godoc.org/builtin#bool)

cmd [[]string](#[]string)

user [?string](#?string)

workdir [?string](#?string)

env [?[]string](#?[]string)
### <a name="Image"></a>type Image


Expand Down
17 changes: 9 additions & 8 deletions cmd/podman/cliconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ type DiffValues struct {

type ExecValues struct {
PodmanCommand
Env []string
Privileged bool
Interfactive bool
Tty bool
User string
Latest bool
Workdir string
PreserveFDs int
DetachKeys string
Comment thread
vrothberg marked this conversation as resolved.
Outdated
Env []string
Privileged bool
Interactive bool
Tty bool
User string
Latest bool
Workdir string
PreserveFDs int
}

type ImageExistsValues struct {
Expand Down
2 changes: 0 additions & 2 deletions cmd/podman/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const remoteclient = false
// Commands that the local client implements
func getMainCommands() []*cobra.Command {
rootCommands := []*cobra.Command{
_execCommand,
_playCommand,
_loginCommand,
_logoutCommand,
Expand Down Expand Up @@ -41,7 +40,6 @@ func getContainerSubCommands() []*cobra.Command {

return []*cobra.Command{
_cleanupCommand,
_execCommand,
_mountCommand,
_refreshCommand,
_runlabelCommand,
Expand Down
1 change: 1 addition & 0 deletions cmd/podman/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var (
_contInspectSubCommand,
_cpCommand,
_diffCommand,
_execCommand,
_exportCommand,
_createCommand,
_initCommand,
Expand Down
32 changes: 19 additions & 13 deletions cmd/podman/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ func init() {
execCommand.SetUsageTemplate(UsageTemplate())
flags := execCommand.Flags()
flags.SetInterspersed(false)
flags.StringVar(&execCommand.DetachKeys, "detach-keys", "", "Override the key sequence for detaching a container. Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _")
flags.StringArrayVarP(&execCommand.Env, "env", "e", []string{}, "Set environment variables")
flags.BoolVarP(&execCommand.Interfactive, "interactive", "i", false, "Not supported. All exec commands are interactive by default")
flags.BoolVarP(&execCommand.Interactive, "interactive", "i", false, "Keep STDIN open even if not attached")
flags.BoolVarP(&execCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.BoolVar(&execCommand.Privileged, "privileged", false, "Give the process extended Linux capabilities inside the container. The default is false")
flags.BoolVarP(&execCommand.Tty, "tty", "t", false, "Allocate a pseudo-TTY. The default is false")
Expand All @@ -45,30 +46,35 @@ func init() {
flags.IntVar(&execCommand.PreserveFDs, "preserve-fds", 0, "Pass N additional file descriptors to the container")
flags.StringVarP(&execCommand.Workdir, "workdir", "w", "", "Working directory inside the container")
markFlagHiddenForRemoteClient("latest", flags)
markFlagHiddenForRemoteClient("preserve-fds", flags)
}

func execCmd(c *cliconfig.ExecValues) error {
args := c.InputArgs
argStart := 1
if len(args) < 1 && !c.Latest {
return errors.Errorf("you must provide one container name or id")
}
if len(args) < 2 && !c.Latest {
return errors.Errorf("you must provide a command to exec")
}
argLen := len(c.InputArgs)
if c.Latest {
argStart = 0
if argLen < 1 {
return errors.Errorf("you must provide a command to exec")
}
} else {
if argLen < 1 {
return errors.Errorf("you must provide one container name or id")
}
if argLen < 2 {
return errors.Errorf("you must provide a command to exec")
}
}
cmd := args[argStart:]
runtime, err := adapter.GetRuntimeNoStore(getContext(), &c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.DeferredShutdown(false)

err = runtime.Exec(c, cmd)
if errors.Cause(err) == define.ErrCtrStateInvalid {
exitCode, err = runtime.ExecContainer(getContext(), c)
if errors.Cause(err) == define.ErrOCIRuntimePermissionDenied {
exitCode = 126
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR but maybe worth checking later: it may be worth add exit codes to the define package as well.

}
if errors.Cause(err) == define.ErrOCIRuntimeNotFound {
exitCode = 127
}
return err
}
3 changes: 3 additions & 0 deletions cmd/podman/healthcheck_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func healthCheckCmd(c *cliconfig.HealthCheckValues) error {
}
defer runtime.DeferredShutdown(false)
status, err := runtime.HealthCheck(c)
if err == nil && status == "unhealthy" {
exitCode = 1
}
fmt.Println(status)
return err
}
1 change: 1 addition & 0 deletions cmd/podman/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var mainCommands = []*cobra.Command{
_diffCommand,
_createCommand,
_eventsCommand,
_execCommand,
_exportCommand,
_generateCommand,
_historyCommand,
Expand Down
20 changes: 20 additions & 0 deletions cmd/podman/varlink/io.podman.varlink
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,23 @@ type DiffInfo(
changeType: string
)

type ExecOpts(
# container name or id
name: string,
# Create pseudo tty
tty: bool,
# privileged access in container
privileged: bool,
# command to execute in container
cmd: []string,
# user to use in container
user: ?string,
# workdir to run command in container
workdir: ?string,
# slice of keyword=value environment variables
env: ?[]string
)

# GetVersion returns version and build information of the podman service
method GetVersion() -> (
version: string,
Expand Down Expand Up @@ -1100,6 +1117,9 @@ method ContainerRestore(name: string, keep: bool, tcpEstablished: bool) -> (id:
# ContainerRunlabel runs executes a command as described by a given container image label.
method ContainerRunlabel(runlabel: Runlabel) -> ()

# ExecContainer executes a command in the given container.
method ExecContainer(opts: ExecOpts) -> ()

# ListContainerMounts gathers all the mounted container mount points and returns them as an array
# of strings
# #### Example
Expand Down
1 change: 1 addition & 0 deletions completions/bash/podman
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,7 @@ _podman_diff() {

_podman_exec() {
local options_with_args="
--detach-keys
-e
--env
--user
Expand Down
11 changes: 8 additions & 3 deletions docs/podman-exec.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ podman\-exec - Execute a command in a running container
**podman exec** executes a command in a running container.

## OPTIONS

**--detach-keys**=*sequence*

Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`.

**--env**, **-e**

You may specify arbitrary environment variables that are available for the
command to be executed.

**--interactive**, **-i**
**--interactive**, **-i**=*true|false*

Not supported. All exec commands are interactive by default.
When set to true, keep stdin open even if not attached. The default is *false*.

**--latest**, **-l**

Instead of providing the container name or ID, use the last created container. If you use methods other than Podman
to run containers such as CRI-O, the last started container could be from either of those methods.
to run containers such as CRI-O, the last started container could be from either of those methods.

The latest option is not supported on the remote client.

Expand Down
4 changes: 1 addition & 3 deletions docs/podman-run.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,7 @@ Path to the container-init binary.

**--interactive**, **-i**=*true|false*

Keep STDIN open even if not attached. The default is *false*.

When set to true, keep stdin open even if not attached. The default is false.
When set to true, keep stdin open even if not attached. The default is *false*.

**--ip6**=*ip*

Expand Down
Loading