Usage
Arguments
Name or ID of the service.
Command and arguments to execute. Defaults to an interactive shell (
bash or sh).Flags
ID of the container to exec into. Accepts full ID or a unique prefix. If not specified, a random container from the service is selected.
-d, --detach
Detached mode - run command in the background.
-T, --no-tty
Disable pseudo-TTY allocation. By default
uc exec allocates a TTY when connected to a terminal.Examples
Start an interactive shell
By default, triesbash first, falls back to sh:
Start a specific shell
Run a command
Execute in a specific container
Use the full container ID or a unique prefix:Pipe input to a command
-T flag disables TTY allocation for piping.
Run a task in the background
Run a database query
Access a service shell with multiple replicas
If a service has multiple replicas, exec connects to a random one:--container:
Interactive Shell
The default command tries to start the best available shell:- First tries
bash - Falls back to
shifbashis not available
Detached Mode
Run a command in the background:Container Selection
If a service has multiple replicas:--container, exec picks a random replica:
--container, target a specific one:
Common Use Cases
Debug application issues
Check running processes
Test database connection
Run database migrations
Access Rails console
Access Django shell
Import data into database
Check environment variables
TTY Behavior
By default,uc exec allocates a pseudo-TTY when:
- stdin is a terminal
- Command is interactive (like a shell)
-T when:
- Piping input:
cat file | uc exec -T service command - Piping output:
uc exec -T service command | grep pattern - Running in CI/CD pipelines
Exit Codes
When running in attached mode (default),uc exec exits with the same code as the executed command:
Related Commands
uc service logs- View container logsuc ps- List containers to get container IDsuc service ls- List services
