如何仅推送Docker push中发生的更改? [英] How to push only whats changed with Docker push?

查看:288
本文介绍了如何仅推送Docker push中发生的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A 。这是我创建映像的方式:

A. Here is how I created the image:


  1. 获得最新的Ubuntu映像

  2. 将Ran作为容器并附加

  3. 从Docker容器内的git中克隆源代码

  4. 标记并推送Docker映像到我的注册表中

  1. Got latest Ubuntu image
  2. Ran as container and attached to it
  3. Cloned source code from git inside docker container
  4. Tagged and pushed docker image to my registry

B 。然后从另一台机器上执行以下操作,拉出,更改和推送了它:

B. And from a different machine I pulled, changed and pushed it by doing:


  1. 从注册表中提取Docker

  2. 以拉出的图像开始容器并附加到容器中

  3. 更改克隆的git目录中的内容

  4. 停止容器,添加标签并将其推入注册表

  1. Docker pull from the registry
  2. Start container with the pulled image and attach to it
  3. Change something in the cloned git directory
  4. Stop container, tag and push it to registry

现在我看到的问题是,每次重复 B 时,它都会尝试上传〜600MB(这是公共映像层)到注册表,在我的情况下需要很长时间。

Now the issue I'm seeing is that every time B is repeated it will try to upload ~600MB (which is the public image layer) to the registry which takes a long time in my case.

有什么方法可以避免上传整个600MB,而是推送唯一更改过的目录?

Is there any way to avoid uploading the whole 600MB and instead pushing the only directory that has changed?

我在做什么错?你们如何使用Docker进行频繁推送?

What am I doing wrong? How do you guys use docker for frequent pushes?

推荐答案

Docker只会推送更改的层,因此看起来好像您的内容工作流程不太正确。如果使用 Dockerfile ,它将更加清晰,因为每条指令都显式创建了一个层,但是即使使用 docker commit 结果应该是相同的。

Docker will only push changed layers, so it looks as though something in your workflow is not quite right. It will be much clearer if you use a Dockerfile, as each instruction explicitly creates a layer, but even with docker commit the results should be the same.

示例-从 ubuntu 图像运行容器并运行 apt-get update ,然后将容器提交到新映像。现在运行 docker history ,您会看到新映像在bash映像的顶部添加了一层,该层具有运行APT更新的附加状态:

Example - run a container from the ubuntu image and run apt-get update and then commit the container to a new image. Now run docker history and you'll see the new images adds a layer on top of the bash image, which has the additional state from running the APT update:

> docker history sixeyed/temp1

IMAGE               CREATED              CREATED BY SIZE                COMMENT
2d98a4114b7c        About a minute ago   /bin/bash                                       22.2 MB
14b59d36bae0        7 months ago         /bin/sh -c #(nop) CMD ["/bin/bash"]             0 B
<missing>           7 months ago         /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/   1.895 kB
<missing>           7 months ago         /bin/sh -c echo '#!/bin/sh' > /usr/sbin/polic   194.5 kB
<missing>           7 months ago         /bin/sh -c #(nop) ADD file:620b1d9842ebe18eaa   187.8 MB

在此情况下, ubuntu 与我的 temp1 图像之间的差异是22MB层 2d98

In this case, the diff between ubuntu and my temp1 image is the 22MB layer 2d98.

现在,如果我从 temp1 运行新容器,则创建一个空文件并运行 docker commit 创建新图像,新层仅具有更改的文件:

Now if I run a new container from temp1, create an empty file and run docker commit to create a new image, the new layer only has the changed file:

> docker history sixeyed/temp2
IMAGE               CREATED              CREATED BY SIZE                COMMENT
e9ea4b4963e4        45 seconds ago       /bin/bash                                       0 B
2d98a4114b7c        About a minute ago   /bin/bash                                       22.2 MB
14b59d36bae0        7 months ago         /bin/sh -c #(nop) CMD ["/bin/bash"]             0 B
<missing>           7 months ago         /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/   1.895 kB
<missing>           7 months ago         /bin/sh -c echo '#!/bin/sh' > /usr/sbin/polic   194.5 kB
<missing>           7 months ago         /bin/sh -c #(nop) ADD file:620b1d9842ebe18eaa   187.8 MB

当我 push 第一个图像,只有22MB的层将被上传-​​其他图像是从 ubuntu 挂载的集线器。如果我推送第二个图像,则仅推送更改的图层-从第一次推送中装入 temp1 图层:

When I push the first image, only the 22MB layer will get uploaded - the others are mounted from ubuntu, which is already in the Hub. If I push the second image, only the changed layer gets pushed - the temp1 layer is mounted from the first push:

> docker push sixeyed/temp2
The push refers to a repository [docker.io/sixeyed/temp2]
f741d3d3ee9e: Pushed
64f89772a568: Mounted from sixeyed/temp1
5f70bf18a086: Mounted from library/ubuntu
6f32b23ac95d: Mounted from library/ubuntu
14d918629d81: Mounted from library/ubuntu
fd0e26195ab2: Mounted from library/ubuntu                          

因此,如果您的推送上传了600MB,则您正在对映像进行600MB更改,或者您的工作流正在阻止Docker正确使用图层。

So if your pushes are uploading 600MB, you're either making 600MB changes to the image, or your workflow is preventing Docker using layers correctly.

这篇关于如何仅推送Docker push中发生的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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