Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
DevOps

Remote Docker builds over SSH: use a VPS as your engine

Point your Docker CLI at a VPS over SSH with docker context, build and run images there, add Buildx for multi-arch images and keep the build box tidy.

CloudSat teamNovember 18, 20267 min read
A thin beam of light linking a small laptop outline to a large glowing server block across a dark field
On this pageWhen a remote engine fits, and when it does not

The docker command on your laptop is only a client. It sends API calls to an engine, and that engine does not have to run on the same machine. Point the client at a Linux server over SSH and every docker build, docker run and docker compose up executes there, while your editor, your files and your habits stay where they are.

People make this switch for practical reasons. Builds stop competing with the browser and the IDE for memory, the build cache lives on a machine that never sleeps, and image pulls and pushes run over a data center uplink instead of home Wi-Fi. Licensing is another: Docker Desktop is free for personal use, education, non-commercial open source and companies with fewer than 250 employees and less than $10 million in annual revenue, while larger organizations need a paid subscription. The Docker CLI and Docker Engine are open-source projects and are not part of that subscription.

When a remote engine fits, and when it does not

Works well Works badly
Heavy builds: compiled languages, large dependency trees Edit and reload loops that bind-mount local source code
amd64 images from an Apple Silicon Mac, built natively Working offline or on a poor connection
Large base images pulled and pushed often Tools that expect localhost to reach your containers
A shared, always-warm build cache for a small team Anything that needs GPU or USB devices on your desk

The last column is mostly about one fact: with a remote engine, "local" means the server. Keep that in mind and the rest of this setup behaves predictably.

How the SSH connection works

With an ssh:// endpoint, the CLI opens an ordinary SSH session to the server and runs docker system dial-stdio there, which bridges the session to the engine's Unix socket. No daemon port is exposed, there are no TLS certificates to manage, and your existing SSH keys, agent and ~/.ssh/config host aliases all apply.

The cost is that the SSH account must be allowed to use the Docker socket on the server. In practice that means membership in the docker group, which is equivalent to root on that machine. Treat the build box as a machine that belongs to whoever can reach it.

Prepare the build box

Use a dedicated server, not your production host. Builds run code from package registries and from your own repository, and a build box that only builds has little else to lose. Install Docker Engine, then create a user for remote access:

# on the server, as root
useradd -m -s /bin/bash -G docker builder
install -d -m 700 -o builder -g builder /home/builder/.ssh
cp ~/.ssh/authorized_keys /home/builder/.ssh/
chown builder:builder /home/builder/.ssh/authorized_keys

Copying root's authorized_keys assumes your own key is already there; otherwise paste your public key into the file instead. Allow key logins only, and leave SSH as the only port open to the internet. A CloudSat server deployed with the Docker one-click app already has Engine, Compose and Buildx installed, which leaves only the user and the firewall to do.

Install only the client on your machine

You need the docker CLI and, for multi-platform builds, the Buildx plugin, but no engine.

Your machine Client-only install
Linux docker-ce-cli, docker-buildx-plugin and docker-compose-plugin from Docker's own package repository
macOS Homebrew's docker, docker-buildx and docker-compose formulas; follow the caveat it prints to register the plugins
Windows Inside WSL, the same packages as Linux; or the static docker.exe binaries Docker publishes for Windows

If you also want a local engine now and then, Colima, Rancher Desktop and Podman Desktop are open-source options that coexist with a remote context.

Create and use a context

A context stores an endpoint under a name, so you can switch between engines without exporting variables:

docker context create vps --description "build box" --docker "host=ssh://builder@203.0.113.10"
docker context ls
docker --context vps info --format '{{.Name}} {{.ServerVersion}}'
docker context use vps            # make it the default for every new shell
docker context use default        # back to the local engine, if you have one

Every CLI call opens an SSH session unless you let SSH reuse one. Docker's documentation suggests connection sharing in ~/.ssh/config, which removes most of the per-command delay:

Host 203.0.113.10
    ControlMaster  auto
    ControlPath    ~/.ssh/control-%C
    ControlPersist yes

For a single terminal, export DOCKER_CONTEXT=vps overrides the default context, and DOCKER_HOST=ssh://builder@203.0.113.10 works without any saved context at all, which suits CI jobs.

Build, run and reach your containers

Builds look exactly as before:

docker build -t registry.example.com/shop/api:1.8.0 .
docker push registry.example.com/shop/api:1.8.0

The build context, meaning the directory you pass to docker build, travels to the server over the SSH connection. A .dockerignore that keeps .git, node_modules, virtual environments and build output out of the context matters more than it does locally, because every unnecessary megabyte crosses the network.

Running containers needs one adjustment in your head. docker run -p 8080:80 nginx publishes port 8080 on the server, not on your laptop. Publish on the server's loopback interface and tunnel to it instead of opening the port to the internet:

docker run -d --name preview -p 127.0.0.1:8080:80 nginx
ssh -N -L 8080:127.0.0.1:8080 builder@203.0.113.10
# now http://localhost:8080 on your laptop reaches the container

Compose follows the same rules. docker --context vps compose up -d --build builds and starts the stack on the server, but a bind mount such as ./data:/data refers to a directory on the server's file system, not on your laptop. Named volumes behave as usual.

Multi-platform images with Buildx

A remote engine on an x86_64 server builds linux/amd64 images natively. For linux/arm64 as well, create a BuildKit builder on top of the context and give the server QEMU emulation:

docker --context vps run --privileged --rm tonistiigi/binfmt --install all
docker buildx create --name vps-builder --driver docker-container --bootstrap vps
docker buildx build --builder vps-builder \
  --platform linux/amd64,linux/arm64 \
  -t registry.example.com/shop/api:1.8.0 --push .

The docker-container driver keeps its results inside the builder, so push multi-platform images straight to a registry with --push. Docker's documentation warns that emulation can be much slower than native builds for compute-heavy steps such as compilation. When that hurts, add a native ARM machine as a second node with docker buildx create --name vps-builder --append <arm-context>, and Buildx sends each platform to the node that runs it natively. Cross-compiling in a multi-stage Dockerfile is the third option, and often the fastest one for languages such as Go that cross-compile easily.

Keep the build box healthy

Build caches only grow. Check them and prune on a schedule:

docker --context vps system df
docker --context vps builder prune --filter until=168h -f
docker buildx prune --builder vps-builder --filter until=168h -f

Builds are CPU and disk heavy and mostly idle between pushes. A plan with fast single-core speed shortens compile steps that do not parallelize, which is what High Frequency VPS plans are built for, and hourly billing means a larger box rented for a release week costs only the hours it exists. Keep base images updated, rebuild rather than patch, and rotate the SSH keys of anyone who leaves the team.

FAQ

Do I still need a Docker Desktop subscription with a remote engine?

The subscription covers Docker Desktop itself. If you no longer install Desktop and use only the open-source CLI with an engine on a Linux server, its terms no longer apply to that workflow. Check your organization's own policy if Desktop is still installed for other reasons.

Can several developers share one build box?

Yes, and they share its cache, which speeds up everyone's builds. Each of them has root-equivalent access to the server through the Docker socket, so share a box only within a team that already trusts each other, and give separate teams separate boxes.

Is this setup slower than a local engine?

Commands that move little data, such as ps or logs, feel the same once SSH connection sharing is on. The build context upload is the main extra cost, which is why .dockerignore matters. The build steps themselves run at the server's speed, so a box with more cores than your laptop helps every parallel compile.

Does Podman support the same thing?

Podman has its own remote mode, podman system connection add, which also runs over SSH. The command names differ, but the model is the same: a thin client on your machine and the engine on the server.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.