Docker映像通过SSH推送(分布式) [英] Docker image push over SSH (distributed)

查看:61
本文介绍了Docker映像通过SSH推送(分布式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR 基本上,我正在寻找这个

TL;DR Basically, I am looking for this:

docker push myimage ssh://myvps01.vpsprovider.net/

我无法掌握整个Docker Hub/Registry背后的原理.我知道我可以运行一个私有注册表,但是为此,我必须设置实际运行服务器的基础结构.

I am failing to grasp the rationale behind whole Docker Hub / Registry thing. I know I can run a private registry, but for that I have to set up the infrastructure of actually running a server.

我偷看了Docker(至少是文件系统)的内部工作原理,看起来Docker映像层或多或少只是一堆压缩文件,带有一些精心设计的文件命名.我很天真地认为,鞭打一个简单的Python脚本来进行分布式推/拉并不是不可能的,但是我当然没有尝试,所以这就是为什么我问这个问题.

I took a sneak peek inside the inner workings of Docker (well, the filesystem at least), and it looks like Docker image layers are just a bunch of tarballs, more or less, with some elaborate file naming. I naïvely think it would not be impossible to whip up a simple Python script to do distributed push/pull, but of course I did not try, so that is why I am asking this question.

有什么技术原因导致Docker无法像Git或Mercurial那样仅进行分布式(无服务器)推/拉?

Are there any technical reasons why Docker could not just do distributed (server-less) push/pull, like Git or Mercurial?

我认为这将是巨大的帮助,因为我可以将在笔记本电脑上构建的图像直接推送到应用程序服务器上,而不是先推送到某个地方的回购服务器,然后再从应用程序服务器中提取.也许我只是误解了这个概念,而注册表是我绝对需要的一个非常重要的功能?

I think this would be a tremendous help, since I could just push the images that I built on my laptop right onto the app servers, instead of first pushing to a repo server somewhere and then pulling from the app servers. Or maybe I have just misunderstood the concept and the Registry is a really essential feature that I absolutely need?

编辑一些希望解释我为什么要这样做的上下文,请考虑以下情形:

EDIT Some context that hopefully explains why I want this, consider the following scenario:

  • 在笔记本电脑上进行开发,测试(OSX,正在运行的Docker计算机,使用docker-compose定义服务和依赖项)
  • 通过脚本(自写,bash,对dev计算机的依赖很少,基本上只是Docker计算机)部署到实时环境中
  • 部署到具有很少依赖性的新VPS,除了SSH访问和Docker守护程序.
  • 没有永久性"服务在任何地方运行,即,我特别不想托管永久运行的注册表(特别是不是所有VPS实例都可以访问,但是可以通过一些巧妙的SSH隧道解决)

当前最好的解决方案是使用Docker机器指向VPS服务器并重建它,但是由于每次我都必须从源构建容器,这会减慢部署速度.

The current best solution is to use Docker machine to point to the VPS server and rebuild it, but it slows down deployment as I have to build the container from source each time.

推荐答案

如果要将Docker映像推送到给定的主机,则Docker中已经存在允许此操作的所有内容.以下示例显示了如何通过ssh推送docker映像:

If you want to push docker images to a given host, there is already everything in Docker to allow this. The following example shows how to push a docker image through ssh:

docker save <my_image> | ssh -C user@my.remote.host.com docker load

  • docker保存会生成一个docker映像的tar存档(包括它的层)
  • -C 用于ssh压缩数据流
  • docker负载从tar归档文件创建docker映像
    • docker save will produce a tar archive of one of your docker images (including its layers)
    • -C is for ssh to compress the data stream
    • docker load creates a docker image from a tar archive
    • 请注意,docker注册表+ docker pull 命令的组合具有仅下载缺少的层的优点.因此,如果您经常更新docker映像(添加新层或修改一些最后的层),则与通过ssh推送完整的docker映像相比, docker pull 命令产生的网络流量会更少.

      Note that the combination of a docker registry + docker pull command has the advantage of only downloading missing layers. So if you frequently update a docker image (adding new layers, or modifying a few last layers) then the docker pull command would generate less network traffic than pushing complete docker images through ssh.

      这篇关于Docker映像通过SSH推送(分布式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆