Hi there! I'm Maneshwar. Right now, I’m building LiveAPI, a first-of-its-kind tool that helps you automatically index API endpoints across all your repositories. LiveAPI makes it easier to discover, understand, and interact with APIs in large infrastructures.
🔄 Build Docker Image Remotely and Run It Locally Using DOCKER_HOST
+ rsync
When you're building Docker images on a remote server but want to run them locally, transferring the image cleanly without pushing to a registry can be annoying. Here's a simple setup using DOCKER_HOST
, rsync
, and docker load
to make this seamless.
Use Case
You want to:
- Build a Docker image on a remote server (
liveapi-prod
) - Transfer it to your local machine
- Run the image locally, either via
docker run
ordocker compose
No Docker registry. No pushing. Just SSH and raw transfer.
The Script
#!/bin/bash
set -e # Exit on error
# Build the image on remote server
DOCKER_HOST=ssh://ubuntu@liveapi-prod docker build -t fw-parse-image .
# Save the image to a tar on remote server
DOCKER_HOST=ssh://ubuntu@liveapi-prod docker save -o fw-parse-image.tar fw-parse-image:latest
# Rsync the tar file to local
rsync -avz --progress ubuntu@liveapi-prod:~/fw-parse-image.tar .
# Load the image into local Docker
docker load -i fw-parse-image.tar
# If you're using Docker Compose, run the container
docker compose up -d fw-parse-container-1
# Or run it manually
# docker run --name fw-parse-container-1 -d fw-parse-image:latest
Breakdown
1. Remote Build Using DOCKER_HOST
DOCKER_HOST=ssh://ubuntu@liveapi-prod docker build -t fw-parse-image .
This line builds the image on the remote server using your local Docker CLI. No need to SSH in or write build scripts on the remote.
2. Save Image on Remote
DOCKER_HOST=ssh://ubuntu@liveapi-prod docker save -o fw-parse-image.tar fw-parse-image:latest
This exports the built image as a .tar
file on the remote server's filesystem.
3. Transfer Image to Local
rsync -avz --progress ubuntu@liveapi-prod:~/fw-parse-image.tar .
This brings the .tar
file down to your local machine, with a progress bar.
4. Load Image Locally
docker load -i fw-parse-image.tar
This brings the image into your local Docker engine so it's ready to run.
5. Run It
Either with Compose:
docker compose up -d fw-parse-container-1
Or directly:
docker run --name fw-parse-container-1 -d fw-parse-image:latest
Extra Tips
- You can wrap this in a Makefile or alias to save time.
- Customize
docker run
if your container needs ports, envs, volumes, etc. - Clean up the
.tar
file after use to free up space.
Why This Is Useful
This approach avoids:
- Pushing to a Docker registry
- SSHing into remote servers manually
- Writing ad-hoc SCP commands or messing with permissions
You control everything from your local terminal — while still offloading builds to a remote box.
LiveAPI helps you get all your backend APIs documented in a few minutes.
With LiveAPI, you can generate interactive API docs that allow users to search and execute endpoints directly from the browser.
If you're tired of updating Swagger manually or syncing Postman collections, give it a shot.
Top comments (0)