# podman exec: Run a Command in a Container

> podman exec runs a command inside a running container. Reference for -it, -e, -u, -w, and the not-running and TTY errors in CI.

Source: https://latchkey.dev/learn/command-reference/podman-exec  
Updated: 2026-06-30

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

| Flag | What it does |
| --- | --- |
| -i, --interactive | Keep stdin open |
| -t, --tty | Allocate 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, --detach | Run 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.

## FAQ

### podman exec: Run a Command in a Container?

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.

### 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
