The container module in Cosmos provides commands to manage Docker containers across your registered hosts.
It allows you to list, run, remove, and restart containers on any host that has Docker installed.
Before managing containers, you must tell cosmos that the host has Docker installed. This is done by setting a host metadata with the following command:
cosmos host set <host> docker bool:trueThis will make the module check the host for containers when listing or managing them.
To unregister a host you can use the following command:
cosmos host unset <host> dockerList all containers across all registered Docker hosts:
cosmos container listThis will display a table of containers, including their name, image, status, and host.
Run a new container on a registered host:
cosmos container run --hostname <host> [...docker flags and args]--hostname, -h: The hostname, IP, or alias of the target host. If not provided, you will be prompted for it.
You will be prompted for any required information if not provided as flags.
Run a hello world container on a registered host:
cosmos container run --h myserver --rm myserver hello-worldRun a temporary Ubuntu container with an interactive shell:
cosmos container run --h myserver --rm -it ubuntu bashRemove one or more containers from a registered host:
cosmos container remove --hostname <host> <container1> [<container2> ...]--hostname, -h: The hostname, IP, or alias of the target host. If not provided, you will be prompted for it.<container1> [<container2> ...]: One or more container names or IDs to remove. You can specify multiple containers separated by spaces. If not provided, you will be prompted for them.
Remove a container named web1 from host myserver:
cosmos container remove --hostname myserver web1Remove multiple containers from host myserver:
cosmos container remove --hostname myserver web1 web2 web3Restart containers on one or more hosts:
cosmos container restart [--hosts <host1,host2,...>] [--names <container1,container2,...>]--hosts, -h: Comma-separated list of hostnames. If omitted, all hosts are targeted (with confirmation).--names, -n: Comma-separated list of container names. If omitted, all containers are targeted (with confirmation).
If no filters are provided, you will be prompted to confirm restarting all containers.
Restart a container named web1 on host myserver:
cosmos container restart --hosts myserver --names web1Restart all containers on multiple hosts:
cosmos container restart --hosts myserver,otherserverRestart all containers on all hosts (with confirmation):
cosmos container restart