Skip to content
Latchkey

podman exec: Run a Command in a Container

podman exec runs a new command inside an already running container, like docker exec.

Use podman exec to run migrations, seed data, or check state inside a service container during a test. In non-interactive CI, drop the -t so it does not demand a TTY.

What it does

podman exec starts an additional process inside a running container. It does not restart the container or its entrypoint; it attaches a new command to the existing namespaces, matching docker exec semantics.

Common usage

Terminal
podman exec db psql -U postgres -c 'SELECT 1'
podman exec -e PGPASSWORD=test db pg_isready
podman exec -it db sh   # interactive (local only)
podman exec -u 0 -w /app app sh -c 'chown -R app /app/data'

Options

FlagWhat it does
-i, --interactiveKeep stdin open
-t, --ttyAllocate a pseudo-TTY (omit in CI)
-e, --env <k=v>Set an environment variable for the command
-u, --user <user>Run as a specific user or UID
-w, --workdir <dir>Working directory for the command
-d, --detachRun the command in the background

In CI

Do not pass -t in pipelines; without a real terminal it fails with "the input device is not a TTY". Use -i alone if the command reads stdin, or neither flag for fire-and-forget commands.

Common errors in CI

"Error: can only create exec sessions on running containers: container state improper" means the target exited; check podman ps -a and podman logs. "the input device is not a TTY" means -t was passed with no terminal; drop it. "Error: executable file not found in $PATH" means the command is not in the image; use sh -c or a full path.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →