{"id":214024,"date":"2021-03-27T10:02:34","date_gmt":"2021-03-27T02:02:34","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=214024"},"modified":"2021-03-22T10:03:21","modified_gmt":"2021-03-22T02:03:21","slug":"docker-migrate","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/docker-migrate.html","title":{"rendered":"\u4ecb\u7ecdDocker\u5bb9\u5668\u8fc1\u79fb\u5230\u5176\u4ed6\u670d\u52a1\u5668\u76845\u79cd\u65b9\u6cd5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fc1\u79fb\u5728\u8bb8\u591a\u60c5\u51b5\u4e0b\u90fd\u662f\u4e0d\u53ef\u907f\u514d\u7684\u3002\u786c\u4ef6\u5347\u7ea7\u3001\u6570\u636e\u4e2d\u5fc3\u53d8\u5316\u3001\u8fc7\u65f6\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u6240\u6709\u8fd9\u4e9b\u90fd\u53ef\u80fd\u6210\u4e3a\u8fc1\u79fb\u7684\u89e6\u53d1\u70b9\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

Docker\u5bb9\u5668\u8fc1\u79fb\u901a\u5e38\u662f\u8fc1\u79fb\u4efb\u52a1\u7684\u4e00\u90e8\u5206\u3002\u4eca\u5929\u6211\u4eec\u5c06\u770b\u5230\u5c06Docker\u5bb9\u5668\u4ece\u73b0\u6709\u670d\u52a1\u5668\u8fc1\u79fb\u5230\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u7684\u4e0d\u540c\u65b9\u6cd5\u3002<\/p>\n

\u5982\u4f55\u5c06Docker\u5bb9\u5668\u8fc1\u79fb\u5230\u53e6\u4e00\u53f0\u670d\u52a1\u5668\uff0c\u6ca1\u6709\u76f4\u63a5\u5c06Docker\u5bb9\u5668\u4ece\u4e00\u53f0\u670d\u52a1\u5668\u8fc1\u79fb\u5230\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u7684\u65b9\u6cd5\uff0c\u6211\u4eec\u901a\u8fc7\u4f7f\u7528\u4e0b\u9762\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u6765\u89e3\u51b3Docker\u5bb9\u5668\u8fc1\u79fb\u7684\u95ee\u9898\u3002<\/p>\n

1\u3001\u5bfc\u51fa\u548c\u5bfc\u5165\u5bb9\u5668<\/strong><\/div>\n

\u5bfc\u51fa\u5bb9\u5668\u610f\u5473\u7740\u4ece\u5bb9\u5668\u7684\u6587\u4ef6\u7cfb\u7edf\u521b\u5efa\u538b\u7f29\u6587\u4ef6\uff0c\u5bfc\u51fa\u7684\u6587\u4ef6\u4fdd\u5b58\u4e3a\u201cgzip\u201d\u6587\u4ef6\u3002<\/p>\n

\r\ndocker export container-name | gzip > container-name.gz \r\n<\/pre>\n

\u7136\u540e\u901a\u8fc7\u6587\u4ef6\u4f20\u8f93\u5de5\u5177(\u5982scp\u6216rsync)\u5c06\u538b\u7f29\u6587\u4ef6\u590d\u5236\u5230\u65b0\u670d\u52a1\u5668\u3002\u5728\u65b0\u670d\u52a1\u5668\u4e2d\uff0c\u8fd9\u4e2agzip\u6587\u4ef6\u968f\u540e\u88ab\u5bfc\u5165\u5230\u4e00\u4e2a\u65b0\u5bb9\u5668\u4e2d\u3002<\/p>\n

\r\nzcat container-name.gz | docker import - container-name \r\n<\/pre>\n

\u53ef\u4ee5\u4f7f\u7528\u201cdocker run\u201d\u547d\u4ee4\u8bbf\u95ee\u5728\u65b0\u670d\u52a1\u5668\u4e2d\u521b\u5efa\u7684\u65b0\u5bb9\u5668\u3002<\/p>\n

\u5bfc\u51fa\u5bb9\u5668\u5de5\u5177\u7684\u4e00\u4e2a\u7f3a\u70b9\u662f\uff0c\u5b83\u4e0d\u5bfc\u51fa\u5bb9\u5668\u7684\u7aef\u53e3\u548c\u53d8\u91cf\uff0c\u4e5f\u4e0d\u5bfc\u51fa\u5305\u542b\u5bb9\u5668\u7684\u5e95\u5c42\u6570\u636e\u3002<\/p>\n

\u5f53\u5c1d\u8bd5\u5728\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u4e2d\u52a0\u8f7d\u5bb9\u5668\u65f6\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9009\u62e9Docker\u955c\u50cf\u8fc1\u79fb\u6765\u5c06\u5bb9\u5668\u4ece\u4e00\u53f0\u670d\u52a1\u5668\u8fc1\u79fb\u5230\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u3002<\/p>\n

2\u3001\u5bb9\u5668\u955c\u50cf\u8fc1\u79fb<\/strong><\/div>\n

\u5c06Docker\u5bb9\u5668\u8fc1\u79fb\u5230\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u7684\u6700\u5e38\u7528\u65b9\u6cd5\u662f\u8fc1\u79fb\u5bb9\u5668\u5173\u8054\u5230\u7684\u955c\u50cf\u3002<\/p>\n

\u5bf9\u4e8e\u5fc5\u987b\u8fc1\u79fb\u7684\u5bb9\u5668\uff0c\u9996\u5148\u4f7f\u7528\u201cDocker commit\u201d\u547d\u4ee4\u5c06\u5176Docker\u955c\u50cf\u4fdd\u5b58\u5230\u538b\u7f29\u6587\u4ef6\u4e2d\u3002<\/p>\n

\r\ndocker commit container-id image-name \r\n<\/pre>\n

\u751f\u6210\u7684\u955c\u50cf\u5c06\u88ab\u538b\u7f29\u5e76\u4e0a\u4f20\u5230\u65b0\u670d\u52a1\u5668\u4e0a\uff0c\u5728\u65b0\u670d\u52a1\u5668\u4e2d\uff0c\u5c06\u4f7f\u7528\u201cdocker run\u201d\u521b\u5efa\u4e00\u4e2a\u65b0\u5bb9\u5668\u3002<\/p>\n

\u4f7f\u7528\u6b64\u65b9\u6cd5\uff0c\u6570\u636e\u5377\u4e0d\u4f1a\u88ab\u8fc1\u79fb\uff0c\u4f46\u5b83\u4f1a\u4fdd\u7559\u5728\u5bb9\u5668\u5185\u521b\u5efa\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u6570\u636e\u3002<\/p>\n

3\u3001\u4fdd\u5b58\u548c\u52a0\u8f7d\u955c\u50cf<\/strong><\/div>\n

docker\u955c\u50cf\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u4ee3\u7801\u3001\u5e93\u3001\u914d\u7f6e\u6587\u4ef6\u7b49\u7684\u5305\u3002Docker\u5bb9\u5668\u662f\u7531\u8fd9\u4e9b\u955c\u50cf\u521b\u5efa\u7684\u3002<\/p>\n

\u53ef\u4ee5\u4f7f\u7528\u201cdocker save\u201d\u538b\u7f29\u955c\u50cf\u5e76\u5c06\u5176\u8fc1\u79fb\u5230\u65b0\u670d\u52a1\u5668\u3002<\/p>\n

\r\ndocker save image-name > image-name.tar \r\n<\/pre>\n

\u5728\u65b0\u670d\u52a1\u5668\u4e2d\uff0c\u4f7f\u7528\u201cdocker load\u201d\u5c06\u538b\u7f29\u955c\u50cf\u6587\u4ef6\u7528\u4e8e\u521b\u5efa\u65b0\u955c\u50cf\u3002<\/p>\n

\r\ncat image-name.tar | docker load \r\n<\/pre>\n
4\u3001\u8fc1\u79fb\u6570\u636e\u5377<\/strong><\/div>\n

Docker\u5bb9\u5668\u4e2d\u7684\u6570\u636e\u5377\u662f\u5171\u4eab\u76ee\u5f55\uff0c\u5176\u4e2d\u5305\u542b\u7279\u5b9a\u4e8e\u5bb9\u5668\u7684\u6570\u636e\u3002\u5377\u4e2d\u7684\u6570\u636e\u662f\u6301\u4e45\u7684\uff0c\u5728\u5bb9\u5668\u91cd\u65b0\u521b\u5efa\u671f\u95f4\u4e0d\u4f1a\u4e22\u5931\u3002<\/p>\n

\u4f7f\u7528\u5bfc\u51fa\u6216\u63d0\u4ea4\u5de5\u5177\u5c06Docker\u5bb9\u5668\u6216\u955c\u50cf\u4ece\u4e00\u53f0\u670d\u52a1\u5668\u8fc1\u79fb\u5230\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u65f6\uff0c\u4e0d\u4f1a\u8fc1\u79fb\u57fa\u7840\u6570\u636e\u5377\u3002<\/p>\n

\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5305\u542b\u6570\u636e\u7684\u76ee\u5f55\u5c06\u624b\u52a8\u8fc1\u79fb\u5230\u65b0\u670d\u52a1\u5668\u3002\u7136\u540e\u5728\u65b0\u670d\u52a1\u5668\u521b\u5efa\u5bb9\u5668\uff0c\u5f15\u7528\u8be5\u76ee\u5f55\u4f5c\u4e3a\u5176\u6570\u636e\u5377\u3002<\/p>\n

\u53e6\u4e00\u4e2a\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u901a\u8fc7\u5728\u201cdocker run\u201d\u547d\u4ee4\u4e2d\u4f20\u9012\u201c-volumes from\u201d\u53c2\u6570\u6765\u5907\u4efd\u548c\u6062\u590d\u6570\u636e\u5377\u3002<\/p>\n

\r\ndocker run --rm --volumes-from datavolume-name -v $(pwd):\/backup image-name tar cvf backup.tar \/path-to-datavolume \r\n<\/pre>\n

\u8fd9\u91cc\uff0cdatavolume\u540d\u79f0\u662f\/path\/to\/volume\u3002\u6b64\u547d\u4ee4\u63d0\u4f9b\u6570\u636e\u5377\u7684\u5907\u4efd\u3002\u8981\u6307\u5b9a\u5de5\u4f5c\u76ee\u5f55\uff0c\u8fd8\u53ef\u4ee5\u6307\u5b9a-w\/backup\u3002\u5728\/backup\u6587\u4ef6\u5939\u4e2d\u751f\u6210\u7684\u5907\u4efd\u53ef\u4ee5\u901a\u8fc7scp\u6216ftp\u5de5\u5177\u590d\u5236\u5230\u65b0\u670d\u52a1\u5668\u3002\u7136\u540e\u63d0\u53d6\u590d\u5236\u7684\u5907\u4efd\u5e76\u5c06\u5176\u8fd8\u539f\u5230\u65b0\u5bb9\u5668\u4e2d\u7684\u6570\u636e\u5377\u4e2d\u3002<\/p>\n

\r\ndocker run --rm --volumes-from datavolume-name -v $(pwd):\/backup image-name bash -c \"cd \/path-to-datavolume && tar xvf \/backup\/backup.tar --strip 1\" \r\n<\/pre>\n
5\u3001\u8fc1\u79fb\u6574\u4e2aDocker\u5bb9\u5668<\/strong><\/div>\n

\u6211\u4eec\u5728\u8fd9\u91cc\u770b\u5230\u7684\u65b9\u6cd5\u9002\u7528\u4e8e\u5355\u4e2a\u5bb9\u5668\u3002\u4f46\u662f\u5c06\u6240\u6709\u5bb9\u5668\u90fd\u8981\u4ece\u4e00\u53f0\u670d\u52a1\u5668\u8fc1\u79fb\u5230\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u91c7\u7528\u53e6\u4e00\u79cd\u65b9\u6cd5\u3002<\/p>\n

\u6b64\u65b9\u6cd5\u5305\u62ec\u5c06\u6574\u4e2adocker\u76ee\u5f55(\u201c\/var\/lib\/docker\u201d)\u590d\u5236\u5230\u65b0\u670d\u52a1\u5668\u3002\u4e3a\u4e86\u4f7f\u8fd9\u79cd\u65b9\u6cd5\u6210\u529f\uff0c\u9700\u8981\u786e\u5b9a\u51e0\u4e2a\u5173\u952e\u70b9\u3002<\/p>\n

    \n\u4fdd\u7559\u6587\u4ef6\u5939\u7684\u6743\u9650\u548c\u6240\u6709\u6743\u3002
    \n\u8fc1\u79fb\u524d\u505c\u6b62Docker\u670d\u52a1\u3002
    \n\u9a8c\u8bc1\u4e24\u53f0\u670d\u52a1\u5668\u4e2d\u7684Docker\u7248\u672c\u662f\u5426\u517c\u5bb9\u3002
    \n\u8fc1\u79fb\u524d\u540e\u9a8c\u8bc1\u5bb9\u5668\u5217\u8868\u548c\u529f\u80fd\u3002
    \n\u73af\u5883\u53d8\u91cf\u548c\u5176\u4ed6\u914d\u7f6e\u6587\u4ef6\u7684\u8def\u5f84\u3002\n<\/ol>\n

    \u5982\u679c\u6b64\u65b9\u6cd5\u7531\u4e8e\u4efb\u4f55\u6545\u969c\u800c\u65e0\u6cd5\u5de5\u4f5c\uff0c\u6211\u4eec\u5c06\u914d\u7f6e\u81ea\u5b9a\u4e49\u811a\u672c\u4ee5\u5c06\u5bb9\u5668\u548c\u955c\u50cf\u4ece\u4e00\u53f0\u670d\u52a1\u5668\u8fc1\u79fb\u5230\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u3002<\/p>\n

    \u7ed3\u8bba\uff1aDocker\u5bb9\u5668\u5e7f\u6cdb\u5e94\u7528\u4e8eDevOps\u548c\u57fa\u4e8eweb\u6258\u7ba1\u3002\u4eca\u5929\u6211\u4eec\u8ba8\u8bba\u4e86Docker\u5de5\u7a0b\u5e08\u5982\u4f55\u5c06Docker\u5bb9\u5668\u8fc1\u79fb\u5230\u6211\u4eec\u7ba1\u7406\u7684Docker\u57fa\u7840\u8bbe\u65bd\u4e2d\u7684\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u7684\u5404\u79cd\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    Docker\u5bb9\u5668\u8fc1\u79fb\u901a\u5e38\u662f\u8fc1\u79fb\u4efb\u52a1\u7684\u4e00\u90e8\u5206\u3002\u4eca\u5929\u6211\u4eec\u5c06\u770b\u5230\u5c06Docker\u5bb9\u5668\u4ece\u73b0\u6709\u670d\u52a1\u5668\u8fc1\u79fb\u5230\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u7684\u4e0d […]<\/p>\n","protected":false},"author":370,"featured_media":116197,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-214024","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/214024","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/370"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=214024"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/214024\/revisions"}],"predecessor-version":[{"id":214028,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/214024\/revisions\/214028"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/116197"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=214024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=214024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=214024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}