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

Deep understanding of the use of ::before/:before and ::after/:after

Part 1: Basics 1. Unlike pseudo-classes such as :...

How to export and import .sql files under Linux command

This article describes how to export and import ....

WeChat applet implements form verification

WeChat applet form validation, for your reference...

How to check disk usage in Linux

1. Use the df command to view the overall disk us...

How to use mysqldump to backup MySQL data

1. Introduction to mysqldump mysqldump is a logic...

Security considerations for Windows server management

Web Server 1. The web server turns off unnecessar...

Introduction to Docker Quick Deployment of SpringBoot Project

1. Install Docker First open the Linux environmen...

Docker nginx + https subdomain configuration detailed tutorial

Today I happened to be helping a friend move his ...

One line of code solves various IE compatibility issues (IE6-IE10)

x-ua-compatible is used to specify the model for ...

How to update, package, and upload Docker containers to Alibaba Cloud

This time, we will try to package the running con...

A brief discussion on the use of GROUP BY and HAVING in SQL statements

Before introducing the GROUP BY and HAVING clause...

JS implements city list effect based on VUE component

This article example shares the specific code for...

What does the "a" in rgba mean? CSS RGBA Color Guide

RGBA is a CSS color that can set color value and ...

Analysis and Solution of ERROR:2002 Reported When MySQL Starts

Preface This article mainly introduces the analys...