{"action":"opened","issue":{"url":"https://api.github.com/repos/docker/docker/issues/15299","labels_url":"https://api.github.com/repos/docker/docker/issues/15299/labels{/name}","comments_url":"https://api.github.com/repos/docker/docker/issues/15299/comments","events_url":"https://api.github.com/repos/docker/docker/issues/15299/events","html_url":"https://github.com/docker/docker/issues/15299","id":98996418,"number":15299,"title":"Proposal: Migrate Containers from one storage to another.","user":{"login":"shishir-a412ed","id":4207652,"avatar_url":"https://avatars.githubusercontent.com/u/4207652?v=3","gravatar_id":"","url":"https://api.github.com/users/shishir-a412ed","html_url":"https://github.com/shishir-a412ed","followers_url":"https://api.github.com/users/shishir-a412ed/followers","following_url":"https://api.github.com/users/shishir-a412ed/following{/other_user}","gists_url":"https://api.github.com/users/shishir-a412ed/gists{/gist_id}","starred_url":"https://api.github.com/users/shishir-a412ed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shishir-a412ed/subscriptions","organizations_url":"https://api.github.com/users/shishir-a412ed/orgs","repos_url":"https://api.github.com/users/shishir-a412ed/repos","events_url":"https://api.github.com/users/shishir-a412ed/events{/privacy}","received_events_url":"https://api.github.com/users/shishir-a412ed/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-04T15:29:56Z","updated_at":"2015-08-04T15:29:56Z","closed_at":null,"body":"Problem: \r\nWe have users who are running docker (Production environment), using lvm devmapper on top of loopback devices. Since this storage option is not production ready, we recommend them to switch to a different storage. Being a production environment they don't want to loose their containers when migrating from one storage to another.\r\n\r\nCurrently they can achieve this using docker export/import. However there are some shortcomings with these commands.\r\nLet's take an example.\r\n\r\n1) I have my source docker (devmapper running on loopback devices) running with 1 image {fedora}.\r\n2) I start a container on this image: docker run --name fedora_container -it fedora /bin/bash\r\n3) I make some changes in the container: echo foobar > /home/foobar.txt\r\n4) I stop the container and I want to migrate my images {fedora} and containers {fedora_container} to the new storage.\r\n\r\nCurrent setup:\r\n\r\n1) docker save fedora > fedora.tar\r\n2) docker export -o fedora_container.tar fedora_container [This will tar up the container rootfs including the changes {foobar.txt} we made]\r\n3) Switch to the new storage.\r\n4) docker load < fedora.tar\r\n5) cat fedora_container.tar | docker import - fedora_new:latest\r\n6) Now I can start a container which will have my changes {foobar.txt} on this new image, fedora_new:latest\r\n\r\nShortcomings:\r\n\r\n1) The container on the new storage is based on image {fedora_new} eventhough the original container was based on image {fedora}.\r\n2) The image fedora_new is a completely standalone image which is not based on any image.\r\n    docker inspect -f {{.Parent}} fedora_new = \"\"\r\n3) Any metadata associated with the containers e.g Mount points is lost, since the container is recreated at the new storage.\r\n4) Docker import results into an image (not container). This means if a user is trying to migrate X images and Y Containers.\r\n   At the new storage he will see X+Y Images, and then he has to start all the containers again on these new images.\r\n5) Since docker export tars up the entire rootfs, the tarball is heavy (In our example, we just created one file {foobar.txt} and the tar ball is ~200MB)\r\n\r\nProposal:\r\n\r\n1) docker export with a new flag (--diff-metadata) will create a tarball with only the diff and metadata of the container. {~ 17 Kb in size}\r\n2) docker import will:\r\n        a) createRootfs on the new storage.\r\n        b) Apply diff.\r\n        c) setup metadata.\r\n        d) load the container in the daemon.\r\n\r\nAfter the import the user will see exact replica of `docker images` and `docker ps -a` in the new storage.\r\n\r\nI have a working version of this proposal on my github branch.\r\nhttps://github.com/shishir-a412ed/docker/tree/migrate_containers\r\n\r\nHow to:\r\nEXPORT: docker export -o fedora_container.tar --diff-metadata fedora_container\r\nIMPORT: cat fedora_container.tar|docker import --diff-metadata -\r\n\r\nI am opening this proposal so that we can discuss how to best approach this problem. \r\nYou can also take a look at my implementation, and if you like that approach I can open a PR and we can take it there.\r\n\r\n"}}