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.
On this page
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:
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:
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:
- Publish it —
docker service update --publish-add 5432:5432 db. It changes the service's spec, and the routing mesh opens the port on every node until you remove it again. - A socat helper and an SSH tunnel — run a
socatcontainer or service on the service's network that relays todb:5432, thenssh -Lto the node where the helper listens. Nothing in the stack changes, but it is several steps, a container to clean up afterwards, and an SSH account on that node. A container joins a stack's overlay network only if the network was declaredattachable; a helper service does not need that. - A forward through an agent — what
kubectl port-forwarddoes on Kubernetes, and what swarmexec does on Swarm:
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:
| Kubernetes | Docker Swarm, built in | swarmexec |
|---|---|---|
kubectl exec -it web-7d9f -- sh | SSH to the node, then docker exec | swarmexec 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=web | docker service logs -f web | swarmexec logs -f web |
kubectl get pods -o wide | docker service ps web | swarmexec ps web |
kubectl config use-context prod | docker context use prod | swarmexec 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:
- several services or a whole stack in one stream —
swarmexec logs -f api worker db,swarmexec logs -f --stack shop; - format-aware filtering —
--log-format auto|classic|json|logfmt|gelf|raw,--min-level warn,--grep; - for a service that crash-loops and has nothing running, the last exited container of each slot, with how it ended.
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.
| Tool | Exec into a task on another node | Port-forward, nothing published | Logs of all replicas | On the cluster | Operator access | Interface · licence |
|---|---|---|---|---|---|---|
| swarmexec | yes by service, slot, task or container | yes to one task, loopback | yes also several services, a stack | one agent per node (global service, Docker socket) | client certificate or shared secret; no node account | CLI + TUI · Apache-2.0 |
SSH + docker exec | partly after finding the node | no publish, or a helper | yes docker service logs | nothing | SSH + Docker socket on every node | CLI · part of Docker |
docker -H ssh://, contexts | partly one context per node | no | yes via the manager | nothing | SSH + Docker socket on every node | CLI · part of Docker |
| socat + SSH tunnel | — | partly helper container, tunnel, cleanup | — | a helper while it runs | SSH to a node | CLI · — |
| Portainer | yes console in the browser | no not documented for Swarm | yes in the browser | server + agent per node | Portainer users; fine-grained RBAC in Business Edition | web · CE zlib, BE commercial |
| Swarmpit | no requests closed in 2019 | no | yes in the browser | app stack + agent per node | Swarmpit users | web · EPL-1.0 |
| lazydocker | partly containers of the one host it talks to | no | partly that host's containers | nothing | access to that host's Docker API | TUI · MIT |
| d4s | partly over SSH | yes over SSH | yes | nothing | SSH to the nodes | TUI · Apache-2.0 |
kubectl / k9s | Kubernetes only — the reference model: exec, port-forward and logs against any pod via the API server | built into Kubernetes | kubeconfig + Kubernetes RBAC | CLI / 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
- You want nothing deployed on the cluster. swarmexec needs one agent per
node, and that agent mounts the Docker socket (plus the node's
/sysread-only, for link MTUs) — the same thing its own security scan flags in your services. It is fenced (authenticated requests only, an audit log, an optional policy) andswarmexec downremoves it, but it is there. SSH or d4s deploy nothing. - Your colleagues need a web UI. swarmexec is a CLI and a TUI. Use Portainer or Swarmpit for the browser.
- You run Kubernetes. Use
kubectland k9s. - You only ever read logs.
docker service logsalready covers every replica on every node.
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.
curl -fsSL https://swarmshell.dev/install.sh | sh,
then swarmexec --context prod init — see
Quick start, the recipes,
or the source on GitHub.