Skip to main content

Exec

Execute a command inside a running container on the target node:

$ osapi client container docker exec --id my-nginx --command "ls,-la,/"

Job ID: 550e8400-e29b-41d4-a716-446655440000

Hostname: server1
Exit Code: 0
Stdout: total 80
drwxr-xr-x 1 root root 4096 Jan 15 10:30 .
drwxr-xr-x 1 root root 4096 Jan 15 10:30 ..
...

Execute with environment variables and a working directory:

$ osapi client container docker exec \
--id my-app \
--command "python,-c,import os; print(os.environ['MY_VAR'])" \
--env "MY_VAR=hello" \
--working-dir /app

Target a specific host:

$ osapi client container docker exec \
--id my-nginx \
--command "nginx,-t" \
--target web-01

JSON Output

Use --json to get the full API response:

$ osapi client container docker exec --id my-nginx --command "ls" --json

Flags

FlagDescriptionDefault
--idContainer ID or name to exec in (required)
--commandCommand to execute, comma-separated (required)
--envEnvironment variable in KEY=VALUE format (repeatable)[]
--working-dirWorking directory inside the container
-T, --targetTarget: _any, _all, hostname, or label (group:web)_any
-j, --jsonOutput raw JSON response