Skip to content

Instantly share code, notes, and snippets.

@baudneo
Forked from pouyanh/dimg-over-ssh.md
Created July 13, 2024 16:30
Show Gist options
  • Save baudneo/0844f270dae8d01220cdc478cdae641a to your computer and use it in GitHub Desktop.
Save baudneo/0844f270dae8d01220cdc478cdae641a to your computer and use it in GitHub Desktop.
Docker image transfer over SSH

Sometimes you want to transfer docker images between two linux hosts over SSH. Supposing images are gonna be transferred to 2nd host, There are two options to do that:

  1. Push image to the 2nd host
  2. Pull image from the 1st host

Push to the 2nd host

Here are the Steps:

Save Image {> Compress} > SSH to 2nd Host ({> Decompress} > Load Image)

There has to be an ssh service running on 2nd host.

Compression/Decompression steps are optional and you can ignore them. Any set of tools can be used here (e.g. gzip/gunzip, bzip2/bunzip2, ...). Compressor has to be available on 1st host and Decompressor on 2nd host

Doing it

  • No compression:
docker save alpine:latest | ssh hostname.2nd "docker load"
  • Compression with gzip:
docker save alpine:latest | gzip | ssh hostname.2nd "gunzip | docker load"
  • Compression with bzip:
docker save alpine:latest | bzip2 | ssh hostname.2nd "bunzip2 | docker load"

Pull from the 1st host

Here are the Steps:

SSH to 1st Host (> Save Image {> Compress}) {> Decompress} > Load Image

There has to be an ssh service running on 1st host

Compression/Decompression steps are optional and you can ignore them. Any set of tools can be used here (e.g. gzip/gunzip, bzip2/bunzip2, ...). Compressor has to be available on 1st host and Decompressor on 2nd host

Doing it

  • No compression:
ssh hostname.1st "docker save alpine:latest" | docker load
  • Compression with gzip:
ssh hostname.1st "docker save alpine:latest | gzip" | gunzip | docker load
  • Compression with bzip:
ssh hostname.1st "docker save alpine:latest | bzip2" | bunzip2 | docker load
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment