docker - how can we export/import (or save/load) only the new changes?

瘦欲@ 提交于 2019-12-11 05:59:51

问题


I'm new to docker, Could any one help for below query

  1. Server has a docker image like 1GB Image:ver1 [this image stored has .tar file in server]
  2. In ubuntu PC donwloaded the tar image form server and loads/import the image[Image:ver1] using Docker
  3. A new Image:ver2 is available on the Serever, size is still 1GB but difference with ver1 is only 10MB.

Q1: If it’s possible to “import/load” the new image[Image:ver2] from server, how can we export/import (or save/load) only the new changes[i.e 10MB]?

Q2: if we are able to apply above changes on top o existing image[i.e Image:Ver1], what are the steps to do?


回答1:


Docker is a file based system and for each Pull request, it only pulls out the files which are changed. For example, if suppose you have 1 GB data in a file in a docker image. Now, you added 500MB of data to it. Then, in case of docker pull, it will only pull the changes, i.e the Delta part between the 2 files. So, you are safe and it won't pull all the things separately.

Although, while making a DockerFile, or docker conf file, you should be very careful, as all the lines in a Docker file is stored as a layer in the system. If suppose you have 10 layers in your Docker file, and you are changing the 5th layer, then all the layers after the 5th layer will again be pulled. That is the only catch using Docker. Rest, it will always pull the Delta of changes for each pull request.




回答2:


If you want to save/load tar files of docker images, there's no option to export a partial image. You can send over the full image, move your data to be an external volume that isn't transfered this way, or you can use a docker registry.

The latter is relatively easy to implement, docker includes an image where you can run your own private registry. Pushes and pulls to a docker registry will only send the changed layers, so you can make use of layer caching and structure your Dockerfiles to minimize the number of changed layers.




回答3:


Ok, I've built the tool to create diff (in top layers) of docker images' versions (layer by layer) as a tarball and inflate the original image later.

Note. Works only for changes in top layers.

4-step process:

  1. docker inspect -> make json with old layers' hashes as a json file
  2. Prepare diff based on new image and hashes of old (existing) layers
  3. Transfer diff to target machine
  4. Inflate target image's tar based on diff and old image


来源:https://stackoverflow.com/questions/43320872/docker-how-can-we-export-import-or-save-load-only-the-new-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!