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

Vue implements dynamic circular percentage progress bar

Recently, when developing a small program, I enco...

Centos8.3, docker deployment springboot project actual case analysis

introduction Currently, k8s is very popular, and ...

How to simulate enumeration with JS

Preface In current JavaScript, there is no concep...

CSS border half or partially visible implementation code

1. Use pseudo-classes to display half of the Bord...

Specific usage of textarea's disabled and readonly attributes

disabled definition and usage The disabled attrib...

Solution to the ineffective global style of the mini program custom component

Table of contents Too long to read Component styl...

How to configure Http, Https, WS, and WSS in Nginx

Written in front In today's Internet field, N...

Example of implementing the Graphql interface in Vue

Note: This article is about the basic knowledge p...

Detailed explanation of the sticky position attribute in CSS

When developing mobile apps, you often encounter ...

Detailed explanation of how to use element-plus in Vue3

Table of contents 1. Installation 2. Import in ma...

Database backup in docker environment (postgresql, mysql) example code

Table of contents posgresql backup/restore mysql ...

Seven different color schemes for website design experience

The color matching in website construction is ver...

Encoding problems and solutions when mysql associates two tables

When Mysql associates two tables, an error messag...

Overview of the basic components of HTML web pages

<br />The information on web pages is mainly...