ÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ±¸·ÝºÍ»Ö¸´
ÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ±¸·ÝºÍ»Ö¸´
¼ò½é£º
ÔÚʹÓÃDocker¾ÙÐÐÓ¦ÓóÌÐòµÄÈÝÆ÷»¯°²ÅÅʱ£¬ÎÒÃǾ³£ÐèÒª¶ÔÈÝÆ÷¾ÙÐб¸·ÝºÍ»Ö¸´²Ù×÷¡£±¸·ÝÈÝÆ÷¿ÉÒÔ°ü¹ÜÊý¾ÝµÄÇå¾²ÐÔ£¬¶ø»Ö¸´²Ù×÷¿ÉÒÔ×ÊÖúÎÒÃÇ¿ìËÙ»Ö¸´·ºÆðÎÊÌâµÄÈÝÆ÷¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ±¸·ÝºÍ»Ö¸´£¬Í¬Ê±ÌṩÏêϸµÄ´úÂëʾÀý¡£
ÈÝÆ÷±¸·Ý
ÈÝÆ÷±¸·Ý¿ÉÒÔͨ¹ýµ¼³öÈÝÆ÷¿ìÕյķ½·¨¾ÙÐС£DockerÌṩÁËÒ»¸öÃûΪdocker exportµÄÏÂÁîÀ´ÊµÏÖÈÝÆ÷µÄµ¼³ö¹¦Ð§¡£ÏÂÃæÊÇʹÓøÃÏÂÁî¾ÙÐÐÈÝÆ÷±¸·ÝµÄʾÀý´úÂ룺
# ͨ¹ýÈÝÆ÷ID»òÃû³Æµ¼³öÈÝÆ÷¿ìÕÕ docker export <container_id_or_name> > backup.tar # ½«µ¼³öµÄ¿ìÕÕÉúÑÄΪÍâµØÎļþ£¬¾ÙÐб¸·Ý docker save -o backup.tar <image_name>
µÇ¼ºó¸´ÖÆ
Ö´ÐÐÒÔÉÏÏÂÁîºó£¬»á½«ÈÝÆ÷µÄ¿ìÕÕµ¼³ö²¢ÉúÑÄΪһ¸ö.tarÎļþ£¬ÎÒÃÇ¿ÉÒÔ½«¸ÃÎļþ´æ´¢ÔÚÍâµØ»òÕßÔ¶³ÌЧÀÍÆ÷ÉÏ¡£ÕâÑù×öµÄÀûÒæÊÇ¿ÉÒÔ±£´æÈÝÆ÷µÄËùÓÐÊý¾ÝºÍÉèÖ㬲¢ÇÒ¿ÉÒÔÔÚÐèҪʱ¿ìËÙ»Ö¸´¡£
µã»÷ÏÂÔØ¡°àËÃûÌÃÊý¾Ý»Ö¸´¾Þ½³¡±£»
ÈÝÆ÷»Ö¸´
ÈÝÆ÷µÄ»Ö¸´¿ÉÒÔͨ¹ýµ¼ÈëÈÝÆ÷¿ìÕյķ½·¨¾ÙÐС£DockerͬÑùÌṩÁËÒ»¸öÃûΪdocker importµÄÏÂÁîÀ´ÊµÏÖÈÝÆ÷µÄµ¼È빦Ч¡£ÏÂÃæÊÇʹÓøÃÏÂÁî¾ÙÐÐÈÝÆ÷»Ö¸´µÄʾÀý´úÂ룺
# ͨ¹ýµ¼ÈëÈÝÆ÷¿ìÕյķ½·¨»Ö¸´ÈÝÆ÷ docker import backup.tar <image_name>:<tag>
µÇ¼ºó¸´ÖÆ
Ö´ÐÐÒÔÉÏÏÂÁîºó£¬»áƾ֤±¸·ÝÎļþ½¨ÉèÒ»¸öеľµÏñ£¬²¢¿ÉÖ¸¶¨¾µÏñµÄÃû³Æ¼°°æ±¾±êÇ©¡£È»ºó¿ÉÒÔʹÓÃdocker runÏÂÁîÆô¶¯Ò»¸ö»ùÓڸþµÏñµÄÈÝÆ÷¡£
±¸·ÝÓë»Ö¸´µÄʾÀý³¡¾°
ÏÂÃæÊÇÒ»¸ö±¸·ÝºÍ»Ö¸´ÈÝÆ÷µÄÍêÕûʾÀý³¡¾°£¬°üÀ¨±¸·Ý¡¢É¾³ý¡¢»Ö¸´ÈÝÆ÷µÄ²Ù×÷£º
# Æô¶¯Ò»¸ö²âÊÔÈÝÆ÷ docker run -d --name=my_container nginx # ±¸·ÝÈÝÆ÷¿ìÕÕ docker export my_container > backup.tar # ɾ³ýÈÝÆ÷ docker rm my_container # »Ö¸´ÈÝÆ÷ docker import backup.tar my_image:latest # Æô¶¯»ùÓÚ»Ö¸´ºóµÄ¾µÏñµÄÈÝÆ÷ docker run -d --name=my_container_restored my_image:latest
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊöʾÀýÖУ¬ÎÒÃÇÊ×ÏÈͨ¹ýdocker runÏÂÁîÆô¶¯ÁËÒ»¸öÃûΪmy_containerµÄNginxÈÝÆ÷£»È»ºóʹÓÃdocker exportÏÂÁ¸ÃÈÝÆ÷µ¼³öΪһ¸ö¿ìÕÕÎļþbackup.tar£»Ëæºó£¬Í¨¹ýdocker rmÏÂÁîɾ³ýÁËmy_container£¬Ä£ÄâÈÝÆ÷ɥʧ»òɾ³ýÇéÐΣ»×îºóʹÓÃdocker importÏÂÁî»Ö¸´ÁËbackup.tarÎļþ£¬²¢½¨ÉèÁËÒ»¸öеľµÏñmy_image£»×îºó£¬ÎÒÃÇÔÙ´ÎʹÓÃdocker runÏÂÁîÆô¶¯ÁËÒ»¸öÃûΪmy_container_restoredµÄÈÝÆ÷£¬¸ÃÈÝÆ÷»ùÓÚ»Ö¸´ºóµÄ¾µÏñ¡£
×ܽ᣺
±¾ÎÄÏÈÈÝÁËʹÓÃDocker¾ÙÐÐÈÝÆ÷±¸·ÝºÍ»Ö¸´µÄÒªÁ죬²¢ÌṩÁËÏìÓ¦µÄ´úÂëʾÀý¡£Í¨¹ý±¸·ÝÈÝÆ÷£¬ÎÒÃÇ¿ÉÒÔ°ü¹ÜÓ¦ÓóÌÐòµÄÇå¾²ÐÔ£¬²¢¿ÉÒÔÔÚÎÊÌⱬ·¢Ê±Ñ¸ËÙ»Ö¸´ÈÝÆ÷¡£Ê¹ÓÃDocker¾ÙÐÐÈÝÆ÷±¸·ÝºÍ»Ö¸´ÊǺÜÊÇÖ÷ÒªµÄ£¬¹ØÓÚÒ»Á¬¼¯³ÉºÍÒ»Á¬°²Åŵȳ¡¾°À´ËµÓÈΪÖ÷Òª¡£Ï£Íû¶ÁÕßÄܹ»Í¨¹ý±¾ÎÄÏàʶ²¢ÕÆÎÕÕâÒ»ÊÖÒÕ£¬ÒÔÌá¸ßÊÂÇéЧÂʺÍÈÝÆ÷»¯°²ÅŵÄÇå¾²ÐÔ¡£
ÒÔÉϾÍÊÇÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄ±¸·ÝºÍ»Ö¸´µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡