{"id":5463,"date":"2018-10-10T05:56:04","date_gmt":"2018-10-10T05:56:04","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=5463"},"modified":"2022-10-03T14:25:56","modified_gmt":"2022-10-03T14:25:56","slug":"difference-between-docker-load-and-docker-import","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/difference-between-docker-load-and-docker-import\/","title":{"rendered":"Docker Tutorials: Difference between Docker Load and Docker Import"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5469\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/10\/Docker.png\" alt=\"\" width=\"600\" height=\"315\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/10\/Docker.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/10\/Docker-300x158.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>If you want to &#8220;flatten&#8221; an image and avoid the history which has multiple layers, docker export and import is the best way to do that.<\/p>\n<p><strong>docker save<\/strong> &#8211; docker save will indeed produce a tarball, but with all parent layers, and all tags + versions.<\/p>\n<p><strong>docker export &#8211;<\/strong> docker export does also produce a tarball, but without any layer\/history.<\/p>\n<p>However, once those tarballs are produced, load\/import are there to:<\/p>\n<p><strong>docker import &#8211;<\/strong> docker import creates one image from one tarball which is not even an image (just a filesystem you want to import as an image). Create an empty filesystem image and import the contents of the tarball<\/p>\n<p><strong>docker load &#8211;<\/strong> docker load creates potentially multiple images from a tarred repository (since docker save can save multiple images in a tarball). Loads a tarred repository from a file or the standard input stream<\/p>\n<p>&nbsp;<\/p>\n<p>[CODE]$ docker run -it ubuntu<br>\n$ cd \/opt\/<br>\nroot@20a8011f2e65:\/opt# touch DevOpsSchool.com<br>\nroot@20a8011f2e65:\/opt# ls<br>\nDevOpsSchool.com<\/p>\n<p>CNTRL + P + Q<\/p>\n<p>$ docker ps<br>\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES<br>\n20a8011f2e65 ubuntu &#8220;\/bin\/bash&#8221; 24 seconds ago Up 23 seconds thirsty_wilson<\/p>\n<p>$ docker export -o ubuntu-devops.tar 20a8011f2e65<br>\n$ docker help import<br>\nUsage: docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]<br>\nImport the contents from a tarball to create a filesystem image<\/p>\n<p>Options:<br>\n-c, &#8211;change list Apply Dockerfile instruction to the created image<br>\n&#8211;help Print usage<br>\n-m, &#8211;message string Set commit message for imported image<\/p>\n<p>$ docker import -m&#8221;ubuntu+devopsschool&#8221; ubuntu-devops. tar<br>\nsha256:c9b6e68b24325d86c511cd45071e69cacd185835b427c83f1cecf7e2e001b13e<\/p>\n<p>$ docker images<br>\nREPOSITORY TAG IMAGE ID CREATED SIZE<br>\nc9b6e68b2432 4 seconds ago 69.8MB<\/p>\n<p>$ docker tag c9b6e68b2432 ubuntu-devopsschool.com<br>\n$ docker images<br>\nREPOSITORY TAG IMAGE ID CREATED SIZE<br>\nubuntu-devopsschool.com latest c9b6e68b2432 25 seconds ago 69.8MB<\/p>\n<p>$ docker run -itd ubuntu-devopsschool.com ls \/opt<br>\n04ed9676981d943f85de58b9885f0347f4ed11c96d97546d484173b7fcd48101<\/p>\n<p>$ docker ps<br>\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES<br>\n20a8011f2e65 ubuntu &#8220;\/bin\/bash&#8221; 2 minutes ago Up 2 minutes<\/p>\n<p>$ docker exec 20a8011f2e65 ls \/opt<br>\nDevOpsSchool.com<\/p>\n<p>$ docker history ubuntu-devopsschool.com<br>\nIMAGE CREATED CREATED BY SIZE COMMENT<br>\nc9b6e68b2432 About a minute ago 69.8MB ubuntu+devopsschool[\/CODE]<\/p>\n<p>Docker Tutorials Fundamental To Advanced-2021 Crash Course:- <a href=\"https:\/\/bit.ly\/3hOIbTB\" target=\"_blank\" rel=\"noopener\">https:\/\/bit.ly\/3hOIbTB<\/a><\/p>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_94240\"><iframe loading=\"lazy\"  id=\"_ytid_71586\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_94240\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>If you want to &#8220;flatten&#8221; an image and avoid the history which has multiple layers, docker export and import is the best way to do that. docker save &#8211; docker&#8230; <\/p>\n","protected":false},"author":1,"featured_media":5469,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4862],"tags":[1194,567,2338,1926,5088,5089],"class_list":["post-5463","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker","tag-container","tag-docker","tag-export","tag-import","tag-load","tag-save"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=5463"}],"version-history":[{"count":5,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5463\/revisions"}],"predecessor-version":[{"id":31446,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5463\/revisions\/31446"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/5469"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=5463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=5463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=5463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}