Skip to content

Instantly share code, notes, and snippets.

@pouyanh
Last active March 25, 2019 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pouyanh/2bef079a6c31df18b7c59e6818431f53 to your computer and use it in GitHub Desktop.
Save pouyanh/2bef079a6c31df18b7c59e6818431f53 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