swarmexec

swarmexec › Compared

Swarm exec, compared_

docker exec, logs and port-forward on another Swarm node — every way to do it.

Docker has no docker service exec. The request has been open since October 2016 (moby#27552), and the reason is architectural: the manager knows where every task runs, but a container's shell, its logs, its unpublished ports and its volumes live on one node, and only that node's daemon can reach them. Every tool on this page is a different answer to "how do I get to that daemon". This page compares them honestly — including where swarmexec, the project this site belongs to, is the wrong pick.

How do I exec into a container on another node in Docker Swarm?

docker exec talks to one daemon. Pointed at a manager, it sees the manager's own containers and nothing else, so a task scheduled on node-3 is out of reach. The built-in way is a lookup, an SSH session and a second lookup:

$ docker service ps web -f desired-state=running # which node runs it? $ ssh node-3 node-3$ docker ps -f name=web.2 # which container is it? node-3$ docker exec -it 3f9a2b1c9e04 sh

A docker context per node (docker context create node-3 --docker host=ssh://ops@node-3) saves the interactive SSH step, but not the lookups — and you still need an SSH account on every node whose user may use the Docker socket, which on that node is as good as root. With swarmexec the client does the lookup against the manager and connects to a small agent on the node that runs the task:

$ swarmexec exec web -- sh # a task of the service "web" $ swarmexec exec web.2 -- sh # exactly replica 2 $ swarmexec exec -u root -w /app web -- ls -la

With no command it opens /bin/sh; the remote command's exit code is passed through unchanged, so it works in scripts. A target can be a service, a service.slot, a task id or a container id — see target selectors and the replica recipe.

How do I port-forward to a Docker Swarm service without publishing the port?

Docker has no port-forward command, so a database that is only on an overlay network is reachable from your laptop in one of three ways:

$ swarmexec port-forward db 5432 # 127.0.0.1:5432 → port 5432 in one task of db $ swarmexec pf web.2 9090:8080 # local 9090 → 8080 in replica 2

The forward is TCP, bound to 127.0.0.1 unless you pass --address (anything else prints a warning that the port is reachable from your network), and it goes to exactly one task — a forward that load-balanced across replicas would make debugging misleading. Nothing is published and the service spec is not touched. Details: port-forward, forward a database port.

What is the kubectl exec equivalent for Docker Swarm?

Kubernetes has the model Swarm is missing: the API server knows where a pod runs, and the kubelet on that node carries the stream, so kubectl exec, kubectl logs and kubectl port-forward work against any pod without SSH. swarmexec copies that model onto Swarm, with the manager in the API server's role and a per-node agent in the kubelet's:

KubernetesDocker Swarm, built inswarmexec
kubectl exec -it web-7d9f -- shSSH to the node, then docker execswarmexec exec web.2 -- sh
kubectl port-forward svc/db 5432— (publish, or socat + SSH tunnel)swarmexec port-forward db 5432
kubectl logs -f -l app=webdocker service logs -f webswarmexec logs -f web
kubectl get pods -o widedocker service ps webswarmexec ps web
kubectl config use-context proddocker context use prodswarmexec context use prod, or --context prod
k9s—swarmexec ui

The port spelling is the same as kubectl port-forward's: 8080 for the same port on both sides, 9090:8080 for local:remote. As with kubectl port-forward svc/…, a service target picks one task.

Logs of every replica, and of a whole stack

This is the one job Swarm does well out of the box: docker service logs -f web on a manager streams every replica, from every node, with nothing deployed. If that is all you need, it is enough. swarmexec adds what it lacks for day-to-day debugging:

See logs and follow logs across a whole stack.

Side by side

yes · partly · no. "On the cluster" is what has to run there; "operator access" is what a person needs before they can use it.

ToolExec into a task on another nodePort-forward, nothing publishedLogs of all replicasOn the clusterOperator accessInterface · licence
swarmexecyes by service, slot, task or containeryes to one task, loopbackyes also several services, a stackone agent per node (global service, Docker socket)client certificate or shared secret; no node accountCLI + TUI · Apache-2.0
SSH + docker execpartly after finding the nodeno publish, or a helperyes docker service logsnothingSSH + Docker socket on every nodeCLI · part of Docker
docker -H ssh://, contextspartly one context per nodenoyes via the managernothingSSH + Docker socket on every nodeCLI · part of Docker
socat + SSH tunnel—partly helper container, tunnel, cleanup—a helper while it runsSSH to a nodeCLI · —
Portaineryes console in the browserno not documented for Swarmyes in the browserserver + agent per nodePortainer users; fine-grained RBAC in Business Editionweb · CE zlib, BE commercial
Swarmpitno requests closed in 2019noyes in the browserapp stack + agent per nodeSwarmpit usersweb · EPL-1.0
lazydockerpartly containers of the one host it talks tonopartly that host's containersnothingaccess to that host's Docker APITUI · MIT
d4spartly over SSHyes over SSHyesnothingSSH to the nodesTUI · Apache-2.0
kubectl / k9sKubernetes only — the reference model: exec, port-forward and logs against any pod via the API serverbuilt into Kuberneteskubeconfig + Kubernetes RBACCLI / TUI · Apache-2.0

Third-party entries are checked against each project's own repository and documentation on 2026-11-19 (and the landing page's table on the same day). Something out of date? Open an issue.

Tool by tool

swarmexec vs. SSH and docker exec

Plain SSH needs nothing deployed and nothing new to trust, and for a two-node cluster with one operator it may be all you need. It scales badly in two directions: every exec is two lookups and a login, and every person who needs a shell needs an account on every node — with access to the Docker socket, which is root on that node. swarmexec replaces that with one door per node, the agent, which knows who came in (the certificate's CN, or the operator name with the shared secret), writes an audit line per request, and can refuse per action with a policy file (no exec as root, no forwards to the database ports, …).

swarmexec vs. docker -H ssh:// and docker contexts

A context makes a remote daemon feel local, and it is the right tool for one host. On a Swarm it is one context per node, chosen by hand after docker service ps told you the node; a context on the manager gives you docker service and docker service logs, but its docker exec still only reaches the manager's own containers. swarmexec takes the context you already have — including an ssh:// one — for the manager, and tunnels the agent traffic over the same SSH host when the nodes are not reachable directly. One context per cluster, not per node: see Docker context & SSH.

swarmexec vs. Portainer

Portainer solves the same node-local problem the same way — an agent on every node — and puts a web UI on top: a console into containers on any node, logs, stacks, users and teams, for people who do not live in a terminal. It is the better choice when colleagues need a browser. It has no port-forward to your workstation for Swarm containers that we could find documented, and fine-grained RBAC and activity logs are in the Business Edition — free on up to three nodes, paid above that. swarmexec is terminal-first (scriptable CLI, exit codes for CI, a TUI), Apache-2.0 at any size, and adds a content diff of a stack file against what is deployed and a security check before stack deploy. The two coexist fine.

swarmexec vs. Swarmpit

Swarmpit is a web UI made for Swarm: services, stacks, nodes, logs and resource stats in the browser, with its own agent per node. It does not open a shell in a container — the feature requests for a console (#259, #438) were closed in 2019 without one — and it has no port-forward. If you want a Swarm dashboard, it fits; if you need to get into a task, it does not, and swarmexec is complementary.

swarmexec vs. lazydocker

lazydocker is a well-loved terminal UI "for both docker and docker-compose": containers, images, volumes and logs of the Docker host it talks to. That is its scope — Swarm services, their tasks on other nodes and several clusters at once are not what it is built around. On a single host or a Compose project it is excellent; on a Swarm, swarmexec ui is the cluster-wide equivalent: stacks and services, volumes, networks, secrets, configs and nodes across the whole Swarm, and several clusters in one session (the TUI).

swarmexec and kubectl / k9s

Not alternatives — kubectl and k9s are Kubernetes tools — but the reference swarmexec was built against. If you come from Kubernetes, the table above is the whole translation; the TUI's navigation is k9s-style (tabs, / to filter, one key per action). What Kubernetes gets from the kubelet for free, Swarm needs an agent for, and that is the one thing swarmexec deploys.

swarmexec vs. socat and SSH tunnels

A socat relay on the overlay network plus ssh -L works with nothing but Docker and SSH, and for a one-off it is fine. Each time it is a helper to start on the right network, a tunnel to the right node, and a helper to remove afterwards — and the service name in the relay load-balances across replicas, so you cannot pick which replica you are talking to. swarmexec port-forward is one command, to one chosen task, bound to loopback, stopped with Ctrl-C. Under the hood it uses a helper too — the agent runs a short-lived sidecar in the task's network namespace — but the agent starts it and removes it on its own, about two minutes after the last connection closes (how it works). The TUI's Forwards tab keeps several forwards open at once (Forwards tab).

The close relatives: d4s and swarmcli

Two Go TUIs for Swarm are close in spirit. d4s (Apache-2.0) is deliberately agentless and reaches the daemons over SSH — shell, logs and port-forward with nothing deployed; if you have SSH to every node and want nothing on the cluster, it is the better fit. swarmcli is open core: its Business Edition adds a per-node agent with shell, port-forward and per-user access by client certificate, licensed free of charge on a swarm of up to three nodes and paid above that. swarmexec offers those capabilities wholly under Apache-2.0 with no node limit; the full write-up is in docs/related-work.md.

When swarmexec is the wrong pick

FAQ

Is there a docker service exec command?

No. Docker has no docker service exec; the request (moby/moby#27552) has been open since October 2016. docker exec only reaches containers on the daemon you are talking to, so for a task on another node you have to reach that node's daemon — over SSH, with a docker context per node, or through an agent such as Portainer's or swarmexec's.

How do I exec into a container on another node in Docker Swarm?

Without extra tools: find the node with docker service ps, SSH to it, find the container with docker ps and run docker exec there. With swarmexec, which runs a small agent on every node: swarmexec exec web -- sh, or swarmexec exec web.2 -- sh for a specific replica.

How do I port-forward to a Docker Swarm service without publishing the port?

Docker has no port-forward command. The usual workarounds are publishing the port temporarily with docker service update --publish-add, or a socat helper on the service's overlay network reached through an SSH tunnel. swarmexec port-forward db 5432 listens on 127.0.0.1:5432 and forwards to port 5432 in one task of db, without changing the service or publishing anything.

What is the kubectl exec equivalent for Docker Swarm?

Docker Swarm has none built in. swarmexec follows the kubectl model: swarmexec exec for kubectl exec, swarmexec port-forward for kubectl port-forward, swarmexec logs -f for kubectl logs -f, and swarmexec ui as a k9s-style terminal UI.

Do I need SSH access to every Swarm node to use swarmexec?

No. swarmexec asks the manager which node runs a task and connects to the agent on that node, authenticated with mutual TLS or a connection-bound shared secret. If your Docker context is an ssh:// one, both the manager and the agent traffic go through that one SSH host.

Does swarmexec need anything installed on the cluster?

Yes: one agent per node, deployed as a global Swarm service by swarmexec init and removed again by swarmexec down. The agent mounts the node's Docker socket. If you want nothing on the cluster and already have SSH to every node, an agentless tool such as d4s or plain SSH is the better fit.

Is swarmexec a Portainer alternative?

For operators who live in a terminal, for exec, logs and port-forward: yes. It is not a web UI, so for colleagues who need a browser Portainer remains the better choice. The two can run side by side.

Is swarmexec free?

Yes. It is open source under the Apache License 2.0, with no node limit and no paid edition.

Try it: curl -fsSL https://swarmshell.dev/install.sh | sh, then swarmexec --context prod init — see Quick start, the recipes, or the source on GitHub.