Docker image import and export code examples

Docker image import and export code examples

Import and export of Docker images

This article introduces the import and export of Docker images, which are used in scenarios such as migration, backup, and upgrade. The environment is prepared as follows:

  • CentOS 7.0
  • Docker 1.18

Introduction to import and export commands

The commands involved are export, import, save, load

save

Order

docker save [options] images [images...] 


這里寫圖片描述

Example

docker save -o nginx.tar nginx:latest
Or docker save > nginx.tar nginx:latest
The -o and > indicate output to a file, nginx.tar is the target file, and nginx:latest is the source image name (name:tag)

load command

docker load [options] 


這里寫圖片描述

Example

docker load -i nginx.tar
Or docker load < nginx.tar
-i and < indicate input from a file. The image and related metadata, including tag information, will be successfully imported

export command

docker export [options] container 


這里寫圖片描述

Example

docker export -o nginx-test.tar nginx-test
Where -o means output to a file, nginx-test.tar is the target file, and nginx-test is the source container name (name)

import command

docker import [options] file|URL|- [REPOSITORY[:TAG]] 


這里寫圖片描述

Example

docker import nginx-test.tar nginx:imp
or cat nginx-test.tar | docker import - nginx:imp

the difference

The tar file exported by the export command is slightly smaller than the one exported by the save command.


這里寫圖片描述

  • The export command exports a tar file from a container, while the save command exports from images.
  • Based on the second point, when the exported file is imported back, the entire history of the image (that is, the information of each layer, if you are not familiar with it, you can read Dockerfile) cannot be retained, and rollback operations cannot be performed; save is based on the image, so the information of each layer can be completely retained when importing. As shown in the following figure, nginx:latest is exported by save and imported by load, while nginx:imp is exported by export and imported by import.


這里寫圖片描述

suggestion

  1. You can choose commands based on specific usage scenarios
  2. If you only want to back up images, use save and load. If the container content changes after starting the container and needs to be backed up, use export and import.

This is the end of this article about the import and export code examples of Docker images. For more information about importing and exporting Docker images, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Docker image and container import and export operations practice
  • Implementation of importing and exporting docker images
  • Docker image import, export, backup and migration operations
  • Docker image export, import and copy example analysis
  • How to import and export Docker images
  • How to export and import images between docker
  • Introduction to Docker image import and export process

<<:  vue-cli introduction and installation

>>:  Summarize the common application problems of XHTML code

Recommend

How to implement the prototype pattern in JavaScript

Overview The prototype pattern refers to the type...

Detailed explanation of JavaScript to monitor route changes

Table of contents history pushState() Method push...

The use of MySQL triggers and what to pay attention to

Table of contents About Triggers Use of triggers ...

A brief introduction to web2.0 products and functions

<br />What is web2.0? Web2.0 includes those ...

Common structural tags in XHTML

structure body, head, html, title text abbr, acro...

Summary of common commands for building ZooKeeper3.4 middleware under centos7

1. Download and decompress 1. Introduction to Zoo...

Linux virtual memory settings tutorial and practice

What is Virtual Memory? First, I will directly qu...

A tutorial on how to install, use, and automatically compile TypeScript

1. Introduction to TypeScript The previous articl...

Solution to installing vim in docker container

Table of contents The beginning of the story Inst...

Detailed explanation of Docker usage under CentOS8

1. Installation of Docker under CentOS8 curl http...

Table related arrangement and Javascript operation table, tr, td

Table property settings that work well: Copy code ...

Introduction to HTML basic controls_PowerNode Java Academy

The <input> tag The <input> tag is us...

How to find and delete duplicate rows in MySQL

Table of contents 1. How to find duplicate rows 2...