Docker images export and import operations

Docker images export and import operations

What if the basic images have been configured before and these images are also needed in other places?

Answer: Image import and export functions.

1. Image preservation

[root@wxtest1607 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat8 3.0 90457edaf6ff 6 hours ago 1.036 GB
[root@wxtest1607 lixr]# docker save 9045 > tomcat8-apr.tar
[root@wxtest1607 lixr]# ls -lh
Total dosage: 1.2G
-rw-r--r-- 1 root root 1005M August 24 17:42 tomcat8-apr.tar

2. Image import

Currently I am lacking a CentOS7 server, so the practical approach is to delete the image first and then import it. It's a hassle!

[root@wxtest1607 lixr]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat8 3.0 90457edaf6ff 7 hours ago 1.036 GB
[root@wxtest1607 lixr]# docker rmi 9045
Untagged: tomcat8:3.0
Deleted: sha256:90457edaf6ff4ce328dd8a3131789c66e6bd89e1ce40096b89dd49d6e9d62bc8
Deleted: sha256:00df1d61992f2d87e7149dffa7afa5907df3296f5775c53e3ee731972e253600
[root@wxtest1607 lixr]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@wxtest1607 lixr]# docker load < tomcat8-apr.tar
60685807648a: Loading layer [====================================================>] 442.7 MB/442.7 MB
[root@wxtest1607 lixr]# yer [> ] 527.7 kB/442.7 MB
[root@wxtest1607 lixr]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 90457edaf6ff 7 hours ago 1.036 GB
[root@wxtest1607 lixr]# docker tag 9045 tomcat8-apr:3.0
[root@wxtest1607 lixr]# 
[root@wxtest1607 lixr]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat8-apr 3.0 90457edaf6ff 7 hours ago 1.036 GB

3. Export of container

[root@wxtest1607 lixr]# docker ps 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b91d9ad83efa 9045 "/bin/bash" 18 seconds ago Up 15 seconds trusting_colden
f680b58163ab aa79 "/bin/bash" 8 hours ago Up 8 hours stupefied_mayer
4db6aa9b8278 4052 "mysqld_safe" 21 hours ago Up 21 hours 8080/tcp, 0.0.0.0:53307->3306/tcp nostalgic_leavitt
7bcfe52af7a0 599d "mysqld_safe" 21 hours ago Up 21 hours 8080/tcp, 0.0.0.0:53306->3306/tcp sleepy_hodgkin
[root@wxtest1607 lixr]# 
[root@wxtest1607 lixr]# 
[root@wxtest1607 lixr]# docker export b91d9ad83efa > tomcat80824.tar
[root@wxtest1607 lixr]# ls -lh
Total dosage: 2.1G
-rw-r--r-- 1 root root 943M August 24 18:37 tomcat80824.tar
-rw-r--r-- 1 root root 1005M August 24 17:42 tomcat8-apr.tar

b91d9ad83efa is the container after the image 90457edaf6ff is started.

The file exported by the image is larger than the file exported by the container.

4. Importing containers

[root@wxtest1607 lixr]# docker import tomcat80824.tar
sha256:880fc96a6bb6abdfa949a56d40ef76f32f086fa11024ddcfb4e4e8b22041d5f2
[root@wxtest1607 lixr]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 880fc96a6bb6 6 seconds ago 971.9 MB
[root@wxtest1607 lixr]# docker tag 880f tomcat80824:1.0
[root@wxtest1607 lixr]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat80824 1.0 880fc96a6bb6 About a minute ago 971.9 MB
tomcat8-apr 3.0 90457edaf6ff 8 hours ago 1.036 GB

5. The difference between exporting and importing images and containers

The difference between image import and container import:

1) Container import is to turn the current container into a new image

2) Image import is a copying process

The difference between save and export:

1) save saves all the information of the image - including history

2) Export only exports the current information

[root@wxtest1607 lixr]# docker history 880fc96a6bb6
IMAGE CREATED CREATED BY SIZE COMMENT
880fc96a6bb6 12 minutes ago 971.9 MB Imported from -
[root@wxtest1607 lixr]# docker history 90457edaf6ff
IMAGE CREATED CREATED BY SIZE COMMENT
90457edaf6ff 8 hours ago /bin/bash 434.4 MB      
<missing> 23 hours ago /bin/bash 406.5 MB      
<missing> 7 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B         
<missing> 7 weeks ago /bin/sh -c #(nop) LABEL license=GPLv2 0 B         
<missing> 7 weeks ago /bin/sh -c #(nop) LABEL vendor=CentOS 0 B         
<missing> 7 weeks ago /bin/sh -c #(nop) LABEL name=CentOS Base Imag 0 B         
<missing> 7 weeks ago /bin/sh -c #(nop) ADD file:b3bdbca0669a03490e 194.6 MB      
<missing> 7 weeks ago /bin/sh -c #(nop) MAINTAINER The CentOS Project 0 B

Supplement: Detailed explanation of docker images

docker images is used to view locally downloaded images

[root@localhost ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 1e1148e4cc2c 2 weeks ago 202MB
ubuntu latest 93fd78260bd1 5 weeks ago 86.2MB
REPOSITORY # Image repository TAG # Image tag IMAGE ID # Image ID
CREATED # Image creation time SIZE # Image size

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • Docker images How to build your own native image
  • Solutions to docker images, info, -d and other command errors
  • Docker container custom hosts network access operation
  • Solve the problem that some configuration files in /etc are reset after the docker container is restarted
  • Docker View JVM Memory Usage
  • Docker memory monitoring and stress testing methods
  • Docker View Process, Memory, and Cup Consumption

<<:  Web standards learning to understand the separation of structure and presentation

>>:  js implementation of verification code case

Recommend

The pitfall record of case when judging NULL value in MySQL

Table of contents Preface Mysql case when syntax:...

How to solve the problem of FileZilla_Server:425 Can't open data connection

When installing FileZilla Server on the server, t...

Solve the installation problem of mysql8.0.19 winx64 version

MySQL is an open source, small relational databas...

Example analysis of mysql shared lock and exclusive lock usage

This article uses examples to illustrate the usag...

Writing High-Quality Code Web Front-End Development Practice Book Excerpts

(P4) Web standards are composed of a series of sta...

Solution to Django's inability to access static resources with uwsgi+nginx proxy

When deploying uwsgi+nginx proxy Django, access u...

Problems and solutions of using jsx syntax in React-vscode

Problem Description After installing the plugin E...

Docker FAQ

Docker only maps ports to IPv6 but not to IPv4 St...

Mysql uses insert to insert multiple records to add data in batches

If you want to insert 5 records into table1, the ...

Using JavaScript difference to implement a comparison tool

Preface At work, I need to count the materials su...

Prototype and prototype chain prototype and proto details

Table of contents 1. Prototype 2. Prototype chain...

How to install nginx on win10

Because the company asked me to build a WebServic...

MySQL chooses the appropriate data type for id

Table of contents Summary of Distributed ID Solut...