{"id":465,"date":"2014-09-29T17:13:03","date_gmt":"2014-09-29T22:13:03","guid":{"rendered":"http:\/\/www.virtualroadside.com\/blog\/?p=465"},"modified":"2014-10-06T16:43:53","modified_gmt":"2014-10-06T21:43:53","slug":"easily-transfer-docker-images-between-two-machines-over-the-network","status":"publish","type":"post","link":"http:\/\/www.virtualroadside.com\/blog\/index.php\/2014\/09\/29\/easily-transfer-docker-images-between-two-machines-over-the-network\/","title":{"rendered":"Easily transfer docker images between two machines over the network"},"content":{"rendered":"<p>I&#8217;ve been using docker a lot, and\u00c2\u00a0on occasion I need to transfer images between two machines that are on a local network. If a particular image is large, I might not want to download it twice from two machines, so I download it on one machine and transfer it to the other over the local network.<\/p>\n<p>Now, I could stand up a local docker registry and use that, but it&#8217;s a bit of work. Instead, I&#8217;ve found that the quickest and easiest solution is to combine the docker &#8216;save&#8217; and &#8216;load&#8217; commands with a bit of netcat magic, and it&#8217;s pretty fast and easy. (<strong>Update: <\/strong>you can do it easily using SSH too, see the end of the post). Check it out.<\/p>\n<p>First, on the destination\u00c2\u00a0machine (make sure your firewall allows traffic to the specified port, in this case <em>1234<\/em>):<\/p>\n<pre>nc -v -l 1234 | docker load<\/pre>\n<p>Next, on the source machine, transfer the image (<em>virtuald\/etcd:0.4.6<\/em>) to the destination IP\u00c2\u00a0<em>(192.168.0.42<\/em>):<\/p>\n<pre>docker save virtuald\/etcd:0.4.6 | nc -v 192.168.0.42 1234<\/pre>\n<p>And that&#8217;s it!<\/p>\n<p>The sad thing is that docker save\/load doesn&#8217;t show a status message when saving\/loading, so it might look like it&#8217;s not doing anything. However, using the -v flag for netcat shows when the connection is successfully opened\/closed, so that&#8217;s something.<\/p>\n<p><strong>Security warning:\u00c2\u00a0<\/strong>Obviously, running netcat like this is a *huge* security hole while its up and listening, as anyone who can connect to the port can upload arbitrary images into your docker registry. This is mitigated a bit since netcat will immediately disconnect after the first client disconnects, but still risky on an untrusted network. <span style=\"text-decoration: underline;\">Only use this on trusted networks<\/span>!<\/p>\n<p><strong>Note:\u00c2\u00a0<\/strong>due to <a href=\"https:\/\/github.com\/docker\/docker\/issues\/3877\">this bug<\/a>, you&#8217;ll want to be using docker 1.2+, otherwise you may get unexpected results.<\/p>\n<p><strong>Update! <\/strong>As <a href=\"http:\/\/www.virtualroadside.com\/blog\/index.php\/2014\/09\/29\/easily-transfer-docker-images-between-two-machines-over-the-network\/comment-page-1\/#comment-170185\">Joshua Barratt<\/a> points out, since this method generalizes to any transport that allows piping via stdin\/stdout, you can also do the transfer via SSH too, which is certainly more secure. Use the -C option to enable compression for faster transfers (thanks <a href=\"http:\/\/www.virtualroadside.com\/blog\/index.php\/2014\/09\/29\/easily-transfer-docker-images-between-two-machines-over-the-network\/comment-page-1\/#comment-171587\">Andreas Steffan<\/a>).<\/p>\n<pre>docker save virtuald\/etcd:0.4.6 | ssh -C 192.168.0.42 \u00e2\u20ac\u02dcdocker load\u00e2\u20ac\u2122<\/pre>\n<p><strong>Update II:\u00c2\u00a0<\/strong>As a number of people have pointed out, you can use PV to show a status message:<\/p>\n<pre>docker save virtuald\/etcd:0.4.6 | pv | ssh -C 192.168.0.42 'docker load'<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been using docker a lot, and\u00c2\u00a0on occasion I need to transfer images between two machines that are on a local network. If a particular image is large, I might not want to download it twice from two machines, so I download it on one machine and transfer it to the other over the local [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59,47],"tags":[],"_links":{"self":[{"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/465"}],"collection":[{"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=465"}],"version-history":[{"count":8,"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/465\/revisions"}],"predecessor-version":[{"id":473,"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/465\/revisions\/473"}],"wp:attachment":[{"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}