Stop
Stop a container.
Runs docker stop, which waits timeout seconds before docker kills the container, or docker's default of 10 when it is 0. A container that does not run reports changed: false.
osapi client node docker stop [flags]
Examples
# Stop a container
osapi client node docker stop --target web-01 --name osapitest --timeout 1
# A container that does not run
osapi client node docker stop --target web-01 --name osapitest --timeout 1
Result
Stop a container, on one host:
$ osapi client node docker stop --target web-01 --name osapitest --timeout 1 Results: HOSTNAME STATUS NAME ID web-01 changed osapitest 1 host: 1 changed job 550e8400-e29b-41d4-a716-446655440000 trace 26e448c9dbe1c4a8d216a98c675079c9
On each host, where one cannot run it:
$ osapi client node docker stop --target _all --name osapitest --timeout 1 Results: HOSTNAME STATUS NAME ID web-01 changed osapitest web-02 changed osapitest 3 hosts: 2 changed, 1 skipped job 550e8400-e29b-41d4-a716-446655440000 trace 26e448c9dbe1c4a8d216a98c675079c9 Details: mac-01 skipped operation not supported on this OS family
With --json, the API's response:
{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"changed": true,
"hostname": "web-01",
"name": "osapitest",
"status": "ok"
}
]
}
A container that does not run, on one host:
$ osapi client node docker stop --target web-01 --name osapitest --timeout 1 Results: HOSTNAME STATUS NAME ID web-01 ok osapitest 1 host: 1 ok job 550e8400-e29b-41d4-a716-446655440000 trace 26e448c9dbe1c4a8d216a98c675079c9
On each host, where one cannot run it:
$ osapi client node docker stop --target _all --name osapitest --timeout 1 Results: HOSTNAME STATUS NAME ID web-01 ok osapitest web-02 ok osapitest 3 hosts: 2 ok, 1 skipped job 550e8400-e29b-41d4-a716-446655440000 trace 26e448c9dbe1c4a8d216a98c675079c9 Details: mac-01 skipped operation not supported on this OS family
With --json, the API's response:
{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"changed": false,
"hostname": "web-01",
"name": "osapitest",
"status": "ok"
}
]
}
With the default settings, each example does this on the host:
| Example | On the host |
|---|---|
| Stop a container | runs docker stop -t 1 osapitest |
The command fails in these cases:
| Call | Flags | Fails with |
|---|---|---|
| A container that the host does not have | --name nothere | not found |
| A name that is an option | --name -f | container_id |
| A timeout longer than 300 seconds | --name osapitest --timeout 301 | max |
| A negative timeout | --name osapitest --timeout -1 | min |
Permission
It needs the docker:execute permission.
osapi controller role get --name <role> shows what a role grants.
Flags
| Flag | Description | Default |
|---|---|---|
--name | The container's name or ID (required) | |
-T, --target | Target: _all, _any, hostname, or label (group:web.dev) | _all |
--timeout | Seconds to wait before docker kills it; docker's default when 0 |
Global flags
| Flag | Description | Default |
|---|---|---|
-d, --debug | Enable or disable debug mode | |
-j, --json | Enable JSON output | |
-f, --osapi-file | Path to config file; without one at the default path, osapi runs on the defaults | /etc/osapi/osapi.yaml |
--url | Base URL the CLI client connects to (controller.client.url) | https://localhost:8080 |
Output tells how the result is printed, and what --json
gives.