Use simple string instead of JSON string for pre/post update commands.

This commit is contained in:
Alexandre Menif 2018-06-18 19:37:32 +02:00
parent 25c7853f03
commit 78a375f86e
5 changed files with 26 additions and 88 deletions

View file

@ -280,35 +280,23 @@ docker run -d \
For every container that could be updated by watchtower, it is possible to
specify a command that will be executed before stopping the container (a
`pre-update` command), and a command that will be executed after restarting the
container (a `post-update` command).
These commands are specified using the *com.centurylinklabs.watchtower.pre-update-command*
and the *com.centurylinklabs.watchtower.post-update-command* labels. The values
of these labels are JSON formatted strings that describes the commands.
container (a `post-update` command). These commands are specified using the
*com.centurylinklabs.watchtower.pre-update-command* and the
*com.centurylinklabs.watchtower.post-update-command* labels.
These labels can be declared as instructions in a Dockerfile:
```docker
LABEL com.centurylinklabs.watchtower.pre-update-command='{"Cmd": ["sh", "-c", "/dump-data.sh"]}'
LABEL com.centurylinklabs.watchtower.post-update-command='{"Cmd": ["sh", "-c", "/restore-data.sh"]}'
LABEL com.centurylinklabs.watchtower.pre-update-command="/dump-data.sh"
LABEL com.centurylinklabs.watchtower.post-update-command="/restore-data.sh"
```
Or be specified as part of the `docker run` command line:
```bash
docker run -d \
--label=com.centurylinklabs.watchtower.pre-update-command='{"Cmd": ["sh", "-c", "/dump-data.sh"]}' \
--label=com.centurylinklabs.watchtower.post-update-command='{"Cmd": ["sh", "-c", "/restore-data.sh"]}' \
--label=com.centurylinklabs.watchtower.pre-update-command="/dump-data.sh" \
--label=com.centurylinklabs.watchtower.post-update-command="/restore-data.sh" \
someimage
```
The JSON object is made of the following fields:
* `Cmd`: the command to execute, as an array of strings (required)
* `User`: a string representing a username or a UID. It is of the form `user`,
`user:group`, `uid`, or `uid:gid` (optional)
* `Privileged`: `true` if the command should be given extended privileges,
`false` otherwise (optional, default to `false`)
* `Env`: a list of instructions to set enviroment variables, for example
`["FOO=bar", BAZ=quux]` (optional)