Three ways to manage Docker over SSH
You do not need to expose the Docker API to work with containers on a server. SSH is already there, and it is enough.
- Run commands on the server:
ssh user@server docker ps. Nothing to set up. - A Docker context: your local
dockercommand drives the server's Docker through SSH. Best for daily work from a laptop. - A containers panel in your SSH client: the list, logs and actions with a tap, also from a phone.
Wardterm shows the Docker containers of any SSH server, grouped by Compose project, with live logs, a shell and restart. Nothing to install on the server.
How do you run Docker commands over SSH directly?
The simplest way works with any server you can reach:
ssh deploy@203.0.113.10 docker ps ssh deploy@203.0.113.10 'docker logs --tail 50 web' ssh -t deploy@203.0.113.10 docker exec -it web sh Use quotes when the command has options or pipes, and -t when you need an interactive terminal. Our guide to running commands over SSH explains quoting and exit codes.
How do you manage Docker over SSH with a context?
A context tells your local Docker which daemon to talk to. Create one for the server:
docker context create prod --docker "host=ssh://deploy@203.0.113.10" docker context use prod docker ps # runs on the server Everything now runs remotely: docker images, docker stats, docker compose. Switch back with docker context use default. To run one command on another context without switching, add --context:
docker --context prod ps docker context ls The server needs nothing new: no open port, no TLS certificates. It only needs Docker and SSH. Your local machine needs the Docker CLI, which you get with Docker Desktop or the docker package.
One-off: DOCKER_HOST
For a script or a single command, set the variable instead:
DOCKER_HOST=ssh://deploy@203.0.113.10 docker ps Make it faster
Each Docker command opens a new SSH connection. Reuse one with multiplexing in ~/.ssh/config:
Host 203.0.113.10 ControlMaster auto ControlPath ~/.ssh/cm-%r@%h:%p ControlPersist 10m Our guide to SSH multiplexing explains each line.
How do you use docker compose on a remote server?
With the context active, Compose runs on the server:
docker context use prod docker compose up -d docker compose ps docker compose logs -f --tail 100 Two things surprise people. Build contexts in the compose file are read on your machine and sent to the server. Bind mounts, such as ./data:/data, refer to folders on the server. If your compose file and data live on the server, it is often simpler to SSH in and run Compose there.
The Docker commands you use most over SSH
| Task | Command |
|---|---|
| List running containers | docker ps |
| Include stopped ones | docker ps -a |
| Follow logs | docker logs -f --tail 100 web |
| Shell inside | docker exec -it web sh |
| Restart one | docker restart web |
| CPU and memory | docker stats --no-stream |
| Disk used by Docker | docker system df |
| Update a Compose project | docker compose pull && docker compose up -d |
For more on shells in containers, see how to SSH into a Docker container.
Why does Docker say permission denied over SSH?
The message permission denied while trying to connect to the Docker daemon socket means the SSH user cannot use Docker. Two fixes:
- Add the user to the docker group, then sign out and back in:
sudo usermod -aG docker $USER - Or keep Docker behind sudo and run
sudo docker ...on the server.
Know what the first one means: a member of the docker group can start a container that mounts the whole disk, which is root in all but name. Give it only to users who would have sudo anyway.
How do you clean up Docker disk space safely?
A server that builds or pulls images fills its disk over time. Look first, then delete:
docker system df # what uses space docker image prune # dangling images only docker image prune -a # every image no container uses docker builder prune # build cache Be careful with docker system prune --volumes: it deletes unused volumes, and a volume holds data, such as a database you stopped for a minute. When in doubt, list volumes with docker volume ls -f dangling=true and delete them one by one.
In Wardterm, Clean up shows how much each item frees, from stopped containers to build cache, and you choose what goes.
How do you manage Docker over SSH from an iPhone or iPad?
Typing docker logs -f on a phone keyboard works, but it is not much fun at 2 a.m. Wardterm has a Containers panel for every SSH server, on iPhone, iPad, Android and Mac. It uses the server's own docker or podman command, so there is nothing to install.
- Containers grouped by Compose project, with state, image and ports, and stopped ones folded away.
- Logs that follow live, Shell in a new session, Restart, Stop and Start.
- For a Compose project: logs of all its containers, the compose file in the editor, and Update images, which pulls and recreates only what changed.
- CPU and memory bars per container, and environment variables hidden until you ask.
- When the user needs sudo for Docker, the app asks for the password once.
The panel also sits in the side panel of a terminal, next to the live server stats. See Docker containers for every action.
Live logs, a shell and restart for every container on your servers, from iPhone, iPad or Mac. Start free.
Originally published on the Wardterm blog.
