使用提交更新泊车位图像,使用小的更改 [英] Updating docker images with small changes using commits

查看:142
本文介绍了使用提交更新泊车位图像,使用小的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想利用缓存/分层码头图像来节省带宽,磁盘空间和花费的时间。


  • 我已经安装了一个Web应用程序停靠点映像,并部署到几个Docker主机中。

  • Docker映像包含我的源代码网络应用程序

  • 我在代码中工作,现在有一个新版本的代码。



如何自动创建上一个最后一张图片上的新的停靠点提交仅包含错误修复?



我的目标是只有需要下载小的bugfix diff才能获得已经下载上一张图像的docker主机的新图像。



这是我目前对此的反思: p>


  • 我可能会使用 docker commit 以某种方式保存图像中的更新。 / li>
  • 但是,如何访问图像内容?

  • 即使如此,我将如何创建我的变化,而不是使用与服务网络应用程序无关的各种工具(git和shell脚本)来混淆原始的Docker图像。

  • 我已经查看了分享代码与另一个Docker将负责更新它。但是卷没有承诺。



感谢您如何实现这一点!



编辑:使用多个Dockerfile看起来是另一种方式,thx http://jpetazzo.github.io/2013/12/01/docker-python-pip-requirements/ 的类似问题。看来我需要在飞行中生成我的docker文件。

解决方案

以下是如何使用 docker commit


  1. 启动一个包含要修改的图像的容器: / p>

      docker运行-t -i IMAGE / bin / bash 

    请注意,您可能想要访问一些主机文件/目录来导入容器中的
    更改:



    #pre> docker运行-t -i -v / host / location:/ mnt / share IMAGE / bin / bash

    然后用Ctrl-D或退出退出。



    如果要在脚本中自动执行此操作,则需要在下一步获取容器
    id。而您将要直接发出命令而不是
    调用bash的交互式会话:

      container_id = $ docker运行-d -v / host / location:/ mnt / share IMAGE / bin / bash -c
    ##任何bash代码
    rsync -av --delete --exclude .git / mnt / share / my / app /
    cd / my / app
    ./autogen.sh


  2. 将修改后的容器文件系统提交为新图像:

      docker commit CONTAINER_ID IMAGE_NAME 

    注意:您可能想要使用与先前启动的IMAGE_NAME相同的IMAGE_NAME
    容器与。这将有效地更新您的图像。


其他问题:




  • 对上一张图片进行的任何修改都应尽量减少最后一张图片上创建的新图层。规则可能取决于您是否使用BTRFS(块级修改实际上将在层中)或AUFS(文件级别修改)。最好是避免用相同的文件替换整个源文件(避免 cp -a git checkout-index ,支持 rsync git checkout )。


  • p>您需要在虚拟机上安装一些工具,以便您可以进行更新(可能 git rsync ...)。但是不要忘记,由于安装的主机容量,您还可以提供脚本(甚至是完整的工具)。


  • 创建的映像不是正统的,不是来自 Dockerfile 。您应该可以从官方的 Dockerfile 定期重建一个全新的图像。或者至少尝试通过将所有图像直接放在一张官方图像上来最小化分层。



I want to leverage caching/layering of docker images to save bandwidth, disk space, and time spent.

Let say:

  • I've a web-app docker image installed and deployed into several docker hosts.
  • The docker image contains source code of my web app.
  • I worked on the code, and now have a new version of the code.

How should I automate the creation of a new docker commit above last image containing only the bugfix ?

My goal is that only the small bugfix diff will be required to download to get the new images for docker hosts that already downloaded previous image.

This is the sate of my current reflexion about it:

  • I'll probably end using docker commit somehow to save update in the image.
  • But how can I access the image content ?
  • And even then, how would I import my changes without cluttering the original docker images with various tools (git and shell scripts) that have nothing to do with serving the web app ?.
  • I've looked at volumes to share the code with another docker that would take care of updating it. But volumes don't get committed.

Thanks for any insight on how to achieve this !

EDIT: Using multiple Dockerfile seems another way to do this, thx http://jpetazzo.github.io/2013/12/01/docker-python-pip-requirements/ for the similar concerns. It seems I'll need to generate my dockerfiles on the fly.

解决方案

Here's how to update an existing image with docker commit.

  1. launch a container with the image you want to modify:

      docker run -t -i IMAGE /bin/bash
    

    Note that you'll probably want to access some host files/directory to import changes in the container:

      docker run -t -i -v /host/location:/mnt/share IMAGE /bin/bash
    

    Then quit with Ctrl-D or exit.

    If you want to automate this in a script, you'll need to get the container id for the next step. And you'll want to issue directly commands instead of calling an interactive session of bash:

      container_id=$(docker run -d -v /host/location:/mnt/share IMAGE /bin/bash -c "
            ## any bash code
            rsync -av --delete --exclude .git /mnt/share /my/app/
            cd /my/app
            ./autogen.sh
        ")
    

  2. Commit your modified container filesystem as a new image:

       docker commit CONTAINER_ID IMAGE_NAME
    

    Note: you could want to use the same IMAGE_NAME than the one you've first launched the container with. This will effectively update your image.

Additional concerns:

  • Any modification carried on a previous image should try to minimize the new layer created upon last image. Rules probably depends if you are using BTRFS (block level modifications will actually be in the 'layer'), or AUFS (file level modifications). The best would be to avoid replacing whole source files with the same files (avoid cp -a, git checkout-index, favor rsync or git checkout).

  • You'll need to install some tools on your VM so that you can make your updates (probably git, rsync ...). But don't forget you could also provide scripts (or even complete tools), thanks to the mounted host volume.

  • The created image is not orthodox and does not come from a Dockerfile. You should probably rebuild a full new image quite regularly from an official Dockerfile. Or at least try to minimize layering by having all your images based directly on one official image.

这篇关于使用提交更新泊车位图像,使用小的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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