-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathswarm-exec.sh
executable file
·22 lines (16 loc) · 1.24 KB
/
swarm-exec.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
set -e
###
### This is an example script on how one can use the swarm-exec service to execute arbitrary docker commands.
### The service creation parameters here are highly opinionated, such as `--restart-condition none`.
### This setting for example doesnt restart the task after a single execution of the passed docker command.
### TODO : Make this script configurable that can take in parameters to feed into these service parameters.
### Till that time, change the service create options to address your requirements.
###
### Example : swarm-exec.sh docker run --net=host --name=myhostcontainer busybox sleep 50000
### This will run a busybox container in all the swarm hosts in host network
VERSION=17.03.0-ce
OUTPUT="$(docker service create --mode=global --restart-condition none --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock mavenugo/swarm-exec:$VERSION $@)"
echo "Your command : \"$@\" is successfully executed in the swarm cluster"
echo "Note: your docker command is executed as a swarm global service. When a new node is added to the cluster or after an upgrade, your command will be automatically executed on the new node. If you want to clean up the service, pls remove it using : "
echo "docker service rm $OUTPUT"