podman-exec(1)

πŸ“¦
version 6.1.4 Β· 7 versions
, in alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu stonking

✨ NAME ✨

podman-exec β€” execute a command in a running container. that's the whole personality, no cap. πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

two ways to spell it, same energy bestie:

podman exec [options] container command [arg ...]

podman container exec [options] container command [arg ...]

🌸 DESCRIPTION 🌸

okay so podman exec runs a command inside a container that is already running. that's it. that's the whole function. the container has to be up and alive, you don't get to start a new one here. πŸ¦‹


πŸ’… OPTIONS πŸ’…

  • --cidfile=file β€” read the ID of the target container out of the file you point at. πŸ“„
  • --detach, -d β€” start the exec session but do not attach to it. the command runs in the background, and the exec session gets automatically removed when it finishes. podman exec prints the ID of the exec session and dips immediately after it starts. πŸ«₯
  • --detach-keys=sequence β€” pick the key sequence for detaching from a container. format is either a single character [a-Z], or one or more ctrl-<value> characters where <value> is one of: a-z, @, ^, [, ,, or _. passing "" disables this whole feature. the default is ctrl-p,ctrl-q.

this option can also be set in containers.conf(5). 🎹

  • --env, -e=env β€” set environment variables.

this option lets you pass arbitrary environment variables that are available for the process to be launched inside of the container. if an environment variable is specified without a value, Podman checks the host environment for a value and sets the variable only if it is set on the host. as a special case, if an environment variable ending in * is specified without a value, Podman searches the host environment for variables starting with the prefix and adds those variables to the container. lowkey magic fr fr. 🌱

  • --env-file=file β€” read in a line-delimited file of environment variables. πŸ“ƒ
  • --interactive, -i β€” when set to true, make stdin available to the contained process. if false, the stdin of the contained process is empty and immediately closed.

if attached, stdin is piped to the contained process. if detached, reading stdin will block until later attached.

⚠️ caveat: Podman will consume input from stdin as soon as it becomes available, even if the contained process doesn't request it. so it's a lil greedy, ok? 😭
  • --latest, -l β€” instead of handing over a container name or ID, just use the last created container. note: the last started container can be from other users of Podman on the host machine.

(this option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines) 🚫

  • --no-session β€” do not create a database session for the exec process. this can improve performance, but the exec session will not be visible to other podman commands. speed vs. being seen, pick your fighter. πŸ’¨
  • --preserve-fd=FD1[,FD2,...] β€” pass down to the process the additional file descriptors specified in the comma separated list. it can be specified multiple times. this option is only supported with the crun OCI runtime. it might be a security risk to use this option with other OCI runtimes.

(this option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines) πŸ”₯

  • --preserve-fds=N β€” pass down to the process N additional file descriptors (in addition to 0, 1, 2). the total FDs are 3+N.

(this option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines) πŸ”’

  • --privileged β€” give extended privileges to this container. the default is false.

by default, Podman containers are unprivileged (=false) and cannot, for example, modify parts of the operating system. this is because by default a container is only allowed limited access to devices. a "privileged" container is given the same access to devices as the user launching the container, with the exception of virtual consoles (/dev/tty\d+) when running in systemd mode (--systemd=always).

a privileged container turns off the security features that isolate the container from the host. dropped Capabilities, limited devices, read-only mount points, Apparmor/SELinux separation, and Seccomp filters are all disabled. due to the disabled security features, the privileged field should almost never be set as containers can easily break out of confinement.

containers running in a user namespace (e.g., rootless containers) cannot have more privileges than the user that launched them.

πŸ’€ bestie do NOT just slap this on. this is the "containers can escape confinement" option. it is not a vibe, it is a hazard. πŸ‘‘ (in the bad way)
  • --tty, -t β€” allocate a pseudo-TTY. the default is false.

when set to true, Podman allocates a pseudo-tty and attach to the standard input of the container. this can be used, for example, to run a throwaway interactive shell.

πŸ“’ NOTE: the --tty flag prevents redirection of standard output. it combines STDOUT and STDERR, it can insert control characters, and it can hang pipes. this option is only used when run interactively in a terminal. when feeding input to Podman, use -i only, not -it. not -it. i said what i said. πŸ™ˆ
  • --user, -u=user[:group] β€” sets the username or UID used and, optionally, the groupname or GID for the specified command. both user and group may be symbolic or numeric.

without this argument, the command runs as the user specified in the container image. unless overridden by a USER command in the Containerfile or by a value passed to this option, this user generally defaults to root.

when a user namespace is not in use, the UID and GID used within the container and on the host match. when user namespaces are in use, however, the UID and GID in the container may correspond to another UID and GID on the host. in rootless containers, for example, a user namespace is always used, and root in the container by default corresponds to the UID and GID of the user invoking Podman. 🧚

  • --workdir, -w=dir β€” working directory inside the container.

the default working directory for running binaries within a container is the root directory (/). the image developer can set a different default with the WORKDIR instruction. the operator can override the working directory by using the -w option. πŸ—‚οΈ


😭 Exit Status 😭

the exit code from podman exec tells you why the command inside the container failed to run, or why it exited. when podman exec exits with a non-zero code, the exit codes follow the chroot standard, so here's the tea:

125 β€” the error is with Podman itself

$ podman exec --foo ctrID /bin/sh; echo $?
Error: unknown flag: --foo
125

126 β€” the contained command cannot be invoked

$ podman exec ctrID /etc; echo $?
Error: container_linux.go:346: starting container process caused "exec: \"/etc\": permission denied": OCI runtime error
126

127 β€” the contained command cannot be found

$ podman exec ctrID foo; echo $?
Error: container_linux.go:346: starting container process caused "exec: \"foo\": executable file not found in $PATH": OCI runtime error
127

Exit code β€” the contained command exit code

$ podman exec ctrID /bin/sh -c 'exit 3'; echo $?
3

🌈 EXAMPLES 🌈

execute command in selected container with a stdin and a tty allocated:

$ podman exec -it ctrID ls

execute command with the overridden working directory in selected container with a stdin and a tty allocated:

$ podman exec -it -w /tmp myCtr pwd

execute command as the specified user in selected container:

$ podman exec --user root ctrID ls

execute command but do not attach to the exec session, leaving the command running in the background:

$ podman exec -d ctrID find /path/to/search -name yourfile

🫢 SEE ALSO 🫢

podman(1), podman-run(1) β€” go read those too, they're giving the same energy. πŸ’œ


πŸ“œ HISTORY πŸ“œ

December 2017, originally compiled by Brent Baudebbaude@redhat.com ⟨mailto:bbaude@redhat.com⟩ ⭐


and that's the whole page bestie!! πŸŽ€ this one lives in the General Commands Manual, filed under podman-exec(1) β€” go exec something iconic, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from