DEV Community

Cover image for Build Docker Image Remotely and Run It Locally Using DOCKER_HOST + rsync
Athreya aka Maneshwar
Athreya aka Maneshwar

Posted on • Edited on

Build Docker Image Remotely and Run It Locally Using DOCKER_HOST + rsync

Hello, I'm Maneshwar. I'm building git-lrc, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. Star Us to help devs discover the project. Do give it a try and share your feedback for improving the product.

## 🔄 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 or docker 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
Enter fullscreen mode Exit fullscreen mode

Breakdown

1. Remote Build Using DOCKER_HOST

DOCKER_HOST=ssh://ubuntu@liveapi-prod docker build -t fw-parse-image .
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

This exports the built image as a .tar file on the remote server's filesystem.

image

3. Transfer Image to Local

rsync -avz --progress ubuntu@liveapi-prod:~/fw-parse-image.tar .
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Or directly:

docker run --name fw-parse-container-1 -d fw-parse-image:latest
Enter fullscreen mode Exit fullscreen mode

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.


With LiveAPI, you can generate interactive API docs that allow users to search and execute endpoints directly from the browser.

Return only the cleaned text without any additional commentary:

git-lrc
*AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.

git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.*

Any feedback or contributors are welcome! It's online, source-available, and ready for anyone to use.

⭐ Star it on GitHub:

GitHub logo HexmosTech / git-lrc

Free, Unlimited AI Code Reviews That Run on Commit




AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.

git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.

See It In Action

See git-lrc catch serious security issues such as leaked credentials, expensive cloud operations, and sensitive material in log statements

git-lrc-intro-60s.mp4

Why

  • 🤖 AI agents silently break things. Code removed. Logic changed. Edge cases gone. You won't notice until production.
  • 🔍 Catch it before it ships. AI-powered inline comments show you exactly what changed and what looks wrong.
  • 🔁 Build a

Top comments (0)