7

I have two worker nodes: worker1 and worker2 and one swarm manager. I'm running all the services in the worker nodes only. I need to run from the manager docker exec to access some of the containers created in the worker nodes but I keep getting that the service is not recognized. I know I can run docker exec in any of the worker nodes and it works fine but I dont want to have to find on which node the service is running and then ssh to the designated node to run docker exec command. Is there a way to do so in swarm or not?

tkyass
  • 2,968
  • 8
  • 38
  • 57

2 Answers2

10

Swarm mode does not currently have a way to run an exec on a running task. You need to find the container and run the exec on the host. You can configure the workers to have a TLS protected port they listen on, which would give you remote access (see docker's guide). And you can lookup the node for each task in a service by checking the output of a docker service ps $service_name.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • Maybe you want add a note that this feature is already tracked by two issues: [github.com - moby/moby - Docker service exec](https://github.com/moby/moby/issues/27552) and [github.com - docker/swarmkit - Support for executing into a task](https://github.com/docker/swarmkit/issues/1895) – Murmel Feb 23 '18 at 09:06
3

If this helps, nowadays you can create the overlay network with --attachable flag to enable any container to join the network. This is great feature as it allows a lot of flexibility.

E.g.

$ docker network create --attachable --driver overlay my-network
$ docker service create --network my-network --name web --publish 80:80 nginx
$ docker run --network=my-network -ti alpine sh
$ wget -qO- web

<!DOCTYPE html>
<html>
<head>
....
ronkot
  • 5,915
  • 4
  • 27
  • 41