What if you wanted a docker exec, but for Docker swarm?
A problem with Docker Swarm and automation with it has been that you can't directly exec into any service from the command line. There exist some workarounds to achieve this behaviour, but in the end you want something similar and as convenient as docker exec
but for services.
Install docker-py and click:
pip3 install docker
pip3 install click
Install the plugin your docker cli (from github)
rm ~/.docker/cli-plugins/docker-swarmproxy
curl -L https://raw.githubusercontent.com/neuroforgede/docker-swarm-proxy/master/docker_swarm_proxy.py -o ~/.docker/cli-plugins/docker-swarmproxy
chmod +x ~/.docker/cli-plugins/docker-swarmproxy
Or copy from a local copy of this repo:
cp docker_swarm_proxy.py ~/.docker/cli-plugins/docker-swarmproxy
chmod +x ~/.docker/cli-plugins/docker-swarmproxy
NOTE: For remote clusters, only usage of the DOCKER_HOST environment variable is supported. Usage of Docker Contexts for switching environments is not supported. For remote clusters we strongly advise against exposing the TCP socket directly. Instead use the SSH tunneling support of docker cli as described here.
docker swarmproxy service exec -it vibrant_bell bash
See all available options:
docker swarmproxy service exec --help
Since swarmproxy uses click under the hood for argument parsing, you have to use --
before any exec command.
This will not work:
docker swarmproxy service exec -it vibrant_bell bash -c 'echo hello'
This will work:
docker swarmproxy service exec -it vibrant_bell -- bash -c 'echo hello'