~/docker/how-copy-local-docker-image-another-host-load-without-repository.md

How to Copy Local Docker Image to Another Host Without Repository and Load

2 min readMarch 23, 2022by Gorav Singal#docker
// TL;DR

docker save image:tag > image.tar, scp the tar to the target host, then docker load < image.tar. No registry needed.

How to Copy Local Docker Image to Another Host Without Repository and Load

Introduction

Consider a scenario where you are building a docker image on your local machine and want to run it on another environment or another host. How would you take your docker image there when you don’t have a repository.

Steps to Save and Transfer Docker Image

Following are the steps:

  • Save the Docker image on your machine, in an archive format
  • Do copy that archive file to another host via scp or whatever
  • Load the docker image on that host
  • Run it

Saving Docker Image

Docker provides a way to save your images in an archive bundle.

Lets assume your docker image name is: my-food-api

Command to save

docker save -o my_food_api.tar my-food-api

If your image is with some tag like latest

docker save -o my_food_api.tar my-food-api:latest

You will have a tar file with name: my_food_api.tar

Copy/Transfer Archive File

I transfer this file to another linux host using scp.

scp my_food_api.tar root@my_host:/target_folder/

Load the Docker Image from Archive File

Now, I have the tar file on that host. I need to load it as docker image.

Run following command:

docker load -i /target_folder/my_food_api.tar

Now, you have that docker image loaded, you can run it the way you want using docker run

Summary in Scripts

To summarize, I have made two scripts, just to make my life easy.

After I build the docker image,

saveAndScp.sh

# Save docker image and scp
rm my_food_api.tar

docker save -o my_food_api.tar my_food_api:latest 

scp my_food_api.tar root@your_host:/target_folder/

refresh_image.sh

# just to be sure that no old image exist before
docker image rm my_food_api:latest

docker load -i /target_folder/my_food_api.tar 

run.sh WHatever is your run command,

docker run -it -d -p 8080:13001 -v /root/config:/apps/conf --env-file /root/application.properties my_food_api:latest

$ subscribe --weekly

One deep dive a week, in your inbox

System design, AI engineering, trading systems and interview prep. Tested code, real numbers. Free, and you can unsubscribe any time.

or read it on gyanbyte.substack.com

Share

Related Posts

How to connect to a running mysql service on host from a docker container on same host

How to connect to a running mysql service on host from a docker container on same host

Introduction I have a host running mysql (not on a container). I have to run an…

Docker: unauthorized: incorrect username or password.

Docker: unauthorized: incorrect username or password.

While running docker commands with some images, I started getting error: The…

Docker image for Drupal 7, and Php extension MongoDB installed.

Docker image for Drupal 7, and Php extension MongoDB installed.

You have drupal 7 image from docker hub, and want to connect tomongo db via php…

Docker Push&#58; How to push your docker image to your organization in hub.docker.com

Docker Push&#58; How to push your docker image to your organization in hub.docker.com

Tag the image, by seeing its image id, from docker images command docker tag 04d…

How to connect Php docker container with Mongo DB docker container

How to connect Php docker container with Mongo DB docker container

Goto your command terminal. Type: This will expose port: 27017 by default. You…

How To Create Admin Subdomain In Cloudflare with Nginx Proxy using Docker with SSL

How To Create Admin Subdomain In Cloudflare with Nginx Proxy using Docker with SSL

Introduction I have my main website, which I run on Lets say: . Now, there is my…

Latest Posts

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

In the previous article I argued that AI is not killing software engineering…

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

A few months back I approved a PR that was almost entirely AI-generated. It…

How to Debug AI-Generated Code: Understand First, Fix Last

How to Debug AI-Generated Code: Understand First, Fix Last

In the last article I wrote about reviewing AI code before it goes in. This one…

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

Every few weeks somebody sends me a scary headline — “AI will replace all…

The Transactional Outbox Pattern: Never Lose an Event Again

The Transactional Outbox Pattern: Never Lose an Event Again

This is one of those patterns that looks like nothing until you get burnt once…

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Here is a question I like to ask in interviews: your bank account shows a…