1. 程式人生 > >Docker升級1.10+遷移映象方法

Docker升級1.10+遷移映象方法

Key points:

  • A more secure foundation for referencing images and layers
  • A new distribution manifest and pull features
  • Upgrading old images will include a migration step
  • A migration tool to minimize migration time

在注意事項裡,後面兩點指明和強調了:可以通過一個遷移工具簡化遷移老映象的過程

Understanding 1.10 migration

從Docker v1.10版本開始,在磁碟定址映象的方式發生了完全的改變

。以前,每個映象(層)會隨機分配一個UUID進行標識,而從v1.10+版本開始,使用一種基於安全雜湊定址映象的方法,此方法相比之前的優點是,避免每個映象(層)分配的ID衝突,同時方便不同映象(層)之間的資料共享。

Starting from v1.10 we completely change the way Docker addresses the image data on disk. Previously, every image and layer used a randomly assigned UUID. In 1.10 we implemented a content addressable method using an ID, based on a secure hash of the image and layer data.
The new method gives users more security, provides a built-in way to avoid ID collisions and guarantee data integrity after pull, push, load, or save. It also brings better sharing of layers by allowing many images to freely share their layers even if they didn’t come from the same build.
Addressing images by their content also lets us more easily detect if something has already been downloaded. Because we have separated images and layers, you don’t have to pull the configurations for every image that was part of the original build chain. We also don’t need to create layers for the build instructions that didn’t modify the filesystem.
Content addressability is the foundation for the new distribution features. The image pull and push code has been reworked to use a download/upload manager concept that makes push and pull much more stable and mitigate any parallel request issues. The download manager also brings retries on failed downloads and better prioritization for concurrent downloads.
We are also introducing a new manifest format that is built on top of the content addressable base. It directly references the content addressable image configuration and layer checksums. The new manifest format also makes it possible for a manifest list to be used for targeting multiple architectures/platforms (…more to come on that later). Moving to the new manifest format will be completely transparent.

Preparing for upgrade

在第一次使用已經更新的Docker daemon啟動容器後,當前容器所依賴的映象會自動地遷移到新的基礎設施。具體是,Docker daemon會根據當前已存在的老映象資料,使用SHA256計算校驗和,當這個過程完成後,所有的老映象都會標記一個新的安全ID。注意,如果映象資料比較大,那麼遷移會佔用一些時間(100MB/s),並且在升級這段時間內,Docker daemon是不會對外服務的

To make your current images accessible to the new model we have to migrate them to content addressable storage. This means calculating the secure checksums for your current data.
All your current images, tags and containers are automatically migrated to the new foundation the first time you start updated Docker daemon. Before loading your container, the Docker daemon will calculate all needed checksums for your current data, and after it has completed, all your images and tags will have brand new secure IDs.
While this is simple operation, calculating SHA256 checksums for your files can take time if you have lots of image data.

On average you should assume that migrator can process data at a speed of 100MB/s. During this time your Docker daemon won’t be ready to respond to requests.

Minimizing migration time

如果想減少和縮短升級的時間,可以使用v1.10-migrator工具,或者使用打包此工具的容器。

If you can accept this one time hit, then upgrading Docker Engine and restarting the daemon will transparently migrate your images. However, if you want to minimize the daemon’s downtime, a migration utility can be run while your old daemon is still running.
This program will find all your current images and calculate the checksums for them. After you upgrade and restart your daemon, the checksum data of the migrated images will already exist, freeing the daemon from that computation work. If new images appeared between the migration and the upgrade, those will be processed at time of upgrade to 1.10.
You can get it from https://github.com/docker/v1.10-migrator/releases.
The migration tool can also be run as a Docker image. While running the migrator image you need to expose your Docker data directory to the container. If you use the default path then it would look like docker run –rm -v /var/lib/docker:/var/lib/docker docker/v1.10-migrator. If you use the devicemapper storage driver, you also need to include –privileged to give the tool access to your storage devices.