Skip to main content

Create

Create a container.

Runs docker create, which pulls the image when the host does not have it. The environment goes on docker's standard input, not in its arguments, which each user of the host can read. auto_start starts the container once it is made. A container of the name that the host has already is not made again, and reports changed: false.

osapi client node docker create [flags]

Examples​

# Create a container
osapi client node docker create --target web-01 --name osapitest --image alpine:3.20 --command sleep --command 300

# A container that the host has
osapi client node docker create --target web-01 --name osapitest --image alpine:3.20 --command sleep --command 300

Result​

Create a container, on one host:

$ osapi client node docker create --target web-01 --name osapitest --image alpine:3.20 --command sleep --command 300
Results:
  HOSTNAME  STATUS   NAME       ID
  web-01    changed  osapitest  3f4e8a1b2c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f7

  1 host: 1 changed   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

On each host, where one cannot run it:

$ osapi client node docker create --target _all --name osapitest --image alpine:3.20 --command sleep --command 300
Results:
  HOSTNAME  STATUS   NAME       ID
  web-01    changed  osapitest  3f4e8a1b2c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f7
  web-02    changed  osapitest  3f4e8a1b2c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f7

  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",
"id": "3f4e8a1b2c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f7",
"name": "osapitest",
"status": "ok"
}
]
}

A container that the host has, on one host:

$ osapi client node docker create --target web-01 --name osapitest --image alpine:3.20 --command sleep --command 300
Results:
  HOSTNAME  STATUS  NAME       ID
  web-01    ok      osapitest  3f4e8a1b2c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f7

  1 host: 1 ok   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

On each host, where one cannot run it:

$ osapi client node docker create --target _all --name osapitest --image alpine:3.20 --command sleep --command 300
Results:
  HOSTNAME  STATUS  NAME       ID
  web-01    ok      osapitest  3f4e8a1b2c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f7
  web-02    ok      osapitest  3f4e8a1b2c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f7

  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",
"id": "3f4e8a1b2c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f7",
"name": "osapitest",
"status": "ok"
}
]
}

With the default settings, each example does this on the host:

ExampleOn the host
Create a containerruns docker create --name osapitest alpine:3.20 sleep 300

The command fails in these cases:

CallFlagsFails with
A name that is an option--name -f --image alpine:3.20container_id
No image--name osapitestrequired
An image that is an option--name osapitest --image --privilegedimage_ref
A hostname that is an option--name osapitest --image alpine:3.20 --container-hostname -xdns_name
A hostname longer than 253 characters--name osapitest --image alpine:3.20 --container-hostname aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaamax
A DNS server that is not an address--name osapitest --image alpine:3.20 --dns nameserverip
A port that is not host:container--name osapitest --image alpine:3.20 --ports 80port_mapping
A bind mount that is not two absolute paths--name osapitest --image alpine:3.20 --volumes data:/datavolume_mapping
No name--image alpine:3.20required

Permission​

It needs the docker:write permission. osapi controller role get --name <role> shows what a role grants.

Flags​

FlagDescriptionDefault
--auto-startStart the container once it is created
--commandThe command, in place of the image's own
--container-hostnameThe hostname inside the container
--dnsThe DNS servers of the container
--envThe environment variables of the container (secrets: NAME=secret://<vault>/<key>)
--imageThe image to run, such as alpine:3.20; docker pulls it when the host does not have it (required)
--nameThe container's name (required)
--portsThe published ports, each host:container, such as 8080:80
-T, --targetTarget: _all, _any, hostname, or label (group:web.dev)_all
--volumesThe bind mounts, each host:container, such as /srv/data:/data

Global flags​

FlagDescriptionDefault
-d, --debugEnable or disable debug mode
-j, --jsonEnable JSON output
-f, --osapi-filePath to config file; without one at the default path, osapi runs on the defaults/etc/osapi/osapi.yaml
--urlBase URL the CLI client connects to (controller.client.url)https://localhost:8080

Output tells how the result is printed, and what --json gives.