Utility to launch and manage containers using YAML based configuration data
paunch
command line utility, or by importing python
package paunch
.debug
command lets you see how individual containers are run,
get configuration information for them, and run them any way you need to.The only state that paunch is aware of is the labels that it sets on running containers, so it is up to the user to keep track of what paunch configs should be running so that others can be deleted on cleanup. For these examples we’re going to store that state in a simple text file:
$ touch paunch-state.txt
We’ll start of by deleting any containers that were started by previous calls
to paunch apply
:
$ paunch --verbose cleanup $(cat paunch-state.txt)
Next we’ll apply a simple hello-world config found in
examples/hello-world.yml
which contains the following:
hello:
image: hello-world
detach: false
Applied by running:
$ paunch --verbose apply --file examples/hello-world.yml --config-id hi
$ echo hi >> paunch-state.txt
A container called hello
will be created, print a Hello World message, then
exit. You can confirm that it still exists by running docker ps -a
.
Now lets try running the exact same paunch apply
command:
$ paunch --verbose apply --file examples/hello-world.yml --config-id hi
This will not make any changes at all due to the idempotency behaviour of paunch.
Lets try again with a unique –config-id:
$ paunch --verbose apply --file examples/hello-world.yml --config-id hi-again
$ echo hi-again >> paunch-state.txt
Doing a docker ps -a
now will show that there are now 2 containers, one
called hello
and the other called hello-(random suffix)
. Lets delete the
one associated with the hi
config-id:
$ cat paunch-state.txt
$ echo hi-again > paunch-state.txt
$ cat paunch-state.txt
$ paunch --verbose cleanup $(cat paunch-state.txt)
Doing a docker ps -a
will show that the original hello
container has been
deleted and hello-(random suffix)
has been renamed to hello
Generally paunch cleanup
will be run first to delete containers for configs
that are no longer apply. Then a series of paunch apply
commands can be run.
If these apply
calls are part of a live upgrade where a mixture of old and
new containers are left running, the upgrade can be completed in the next run
to paunch cleanup
with the updated list of config-id state.
Paunch can also be used as a library by other tools. By default running the
paunch
command won’t affect these other containers due to the different managed_by
label being set on those containers. For example if you wanted to run paunch
commands masquerading as the
heat-agents
docker-cmd hook
then you can run:
paunch --verbose apply --file examples/hello-world.yml --config-id hi --managed-by docker-cmd
This will result in a hello
container being run, which will be deleted the
next time the docker-cmd
hook does its own cleanup
run since it won’t
be aware of a config_id
called hi
.
In many cases the user will want to use the same –config-id with changed config data. The aim of the idempotency behaviour is to leave containers running when their config has not changed, but replace containers which have modified config.
When paunch apply
is run with the same --config-id
but modified config
data, the following logic is applied:
exec
actions will be run regardless, so commands they run may require
their own idempotency behaviourOnly configuration data is used to determine whether something has changed to
trigger replacing the container during apply
. This means that changing the
contents of a file referred to in env_file
will not trigger replacement
unless something else changes in the configuration data (such as the path
specified in env_file
).
The most common reason to restart containers is to have them running with an
updated image. As such it is recommended that stable image tags such as
latest
are not used when specifying the image
, and that changing the
release version tag in the configuration data is the recommended way of
propagating image changes to the running containers.
The paunch debug
command allows you to perform specific actions on a given
container. This can be used to:
The configuration options you will likely be interested in here include:
--file <file> YAML or JSON file containing configuration data
--action <name> Action can be one of: "dump-json", "dump-yaml",
"print-cmd", or "run"
--container <name> Name of the container you wish to manipulate
--interactive Run container in interactive mode - modifies config
and execution of container
--shell Similar to interactive but drops you into a shell
--user <name> Start container as the specified user
--overrides <name> JSON configuration information used to override
default config values
file
is the name of the configuration file to use
containing the configuration for the container you wish to use.
Here is an example of using paunch debug
to start a root shell inside the
test container:
# paunch debug --file examples/hello-world.yml --interactive --shell --user root --container hello --action run
This will drop you an interactive session inside the hello world container starting /bin/bash running as root.
To see how this container is started normally:
# paunch debug --file examples/hello-world.yml --container hello --action print-cmd
You can also dump the configuration of this to a file so you can edit it and rerun it with different a different configuration. This is more useful when there are multiple configurations in a single file:
# paunch debug --file examples/hello-world.yml --container hello --action dump-json > hello.json
You can then use hello.json
as your --file
argument after
editing it to your liking.
You can also add any configuration elements you wish on the command line
to test paunch or debug containers etc. In this example I’m running
the hello container with net=host
.
# paunch debug --file examples/hello-world.yml --overrides '{"net": "host"}' --container hello --action run
The current format is loosely based on a subset of the docker-compose v1 format with modifications. The intention is for the format to evolve to faithfully implement existing formats such as the Kubernetes Pod format.
The top-level of the YAML format is a dict where the keys (generally)
correspond to the name of the container to be created. The following config
creates 2 containers called hello1
and hello2
:
hello1:
image: hello-world
hello2:
image: hello-world
The values are a dict which specifies the arguments that are used when the container is launched. Supported keys which comply with the docker-compose v1 format are as follows:
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.