-
Container] Image Export/Import
- derive
-
import (data)
- labeled
- No labels, later modifications
-
Warehouse] Image Export/Import
- derive
- import (data)
- Import (full command)
Create a simple Docker image
Utilize the docker ps -a command to view the image to be exported.
Container] Image Export/Import
derive
Viewing the image to be exported
[root@localhost ~]# docker ps -a
The docker export command performs an image export.
[root@localhost ~]# docker export 418ae >
import (data)
labeled
Import with cat |docker import - image_name:tag command
# Import with tags ---- The name and tags are as consistent as possible with the original image
[vipsoft@kafka1host docker]$ cat | docker import - nginx:1.20.1
No labels, later modifications
[vipsoft@kafka1host docker]# ll
total 132428
-rw-r--r--. 1 vipsoft root 135605760 Aug 19 15:38
# docker import import (data),There are no mirror names and labels for the
[vipsoft@kafka1host docker]# docker import
sha256:be2f0bed014f5eaf8227e9849f03614944f85f2ac25e7ad261b39bef2799a03a
[vipsoft@kafka1host docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> be2f0bed014f 5 minutes ago 131MB
nacos/nacos-server v2.1.1 5ef6d98bd956 2 years ago 1.06GB
java 8 d23bdf5b1b1b 7 years ago 643MB
# utilization docker tagcommand to make changes ":" Formerly known as mirror name,":"Post-representative mirroring tags
[vipsoft@kafka1host docker]# docker tag be2f0bed nginx:1.21.1
[vipsoft@kafka1host docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx 1.21.1 be2f0bed014f 7 minutes ago 131MB
nacos/nacos-server v2.1.1 5ef6d98bd956 2 years ago 1.06GB
java 8 d23bdf5b1b1b 7 years ago 643MB
Images imported using the docker import command have no image name or tag in the bin, which can be modified using the docker tag command.
Warehouse] Image Export/Import
derive
docker save -o nginx:1.20.1
# : Specifies the name of the zip file after exporting the image, which can be named arbitrarily.
# -o: Specify the name of the exported file, it can be named arbitrarily.
# nginx:1.20.1 : represents the name of the exported image in the repository. The actual name in the repository will be used.
import (data)
# docker load -i image save file location
docker load -i /home/vipsoft/docker/
Note: If you have installed certain commands or configurations in a particular container, when exporting the image, make sure to commit the container to the image first, otherwise the exported image will be re-imported into the new docker, and you will lose the installation commands or configurations.
As shown below, I installed the command to view the network in a certain container, but did not commit the container to the image, and after exporting and then re-importing it to other docker environments, the command can not be changed when executing ifconfig:
docker commit 418ae48f5db8 nginx:1.20.1
Import (full command)
[root@localhost ~]# docker images | grep nginx
nginx 1.20.1 c8d03f6b8b91 2 years ago 133MB
/netrainpublic/nginx latest 90c072ff69fd 4 years ago 287MB
[root@localhost ~]# docker ps -a | grep nginx
418ae48f5db8 nginx:1.20.1 "/docker-entrypoint.…" 18 hours ago Up 18 hours 0.0.0.0:80->80/tcp, :::80->80/tcp nginx
[root@localhost ~]# docker exec -it 418ae /bin/bash
root@418ae48f5db8:/# vi /usr/share/nginx/html/
bash: vi: command not found
root@418ae48f5db8:/# exit
exit
# The container does not have a vi command,commander-in-chief (military) Copy to host for modification
[root@localhost ~]# docker cp 418ae48:/usr/share/nginx/html/ /opt/
[root@localhost ~]# vi /opt/
# commander-in-chief (military)改好的文件 Copy to container
[root@localhost ~]# docker cp /opt/ 418ae48:/usr/share/nginx/html/
# Entering the container,Check if it has been modified
[root@localhost ~]# docker exec -it 418ae /bin/bash
root@418ae48f5db8:/# cat /usr/share/nginx/html/
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="/"></a>.<br/>
Commercial support is available at
<a href="/"></a>.</p>
<p><em>Thank you for using nginx.</em></p>
<b>VipSoft 2024.08.20</b> #addition
</body>
</html>
root@418ae48f5db8:/# exit
[root@localhost ~]# docker images | grep nginx
nginx 1.20.1 c8d03f6b8b91 2 years ago 133MB
/netrainpublic/nginx latest 90c072ff69fd 4 years ago 287MB
[root@localhost ~]# docker ps -a | grep nginx
418ae48f5db8 nginx:1.20.1 "/docker-entrypoint.…" 18 hours ago Up 18 hours 0.0.0.0:80->80/tcp, :::80->80/tcp nginx
# commander-in-chief (military)容器修改后的内容,Submit to mirror
[root@localhost ~]# docker commit 418ae nginx:1.20.1
sha256:b532c001cdda870c5cf3c689d720b39571f160071671758ae899aed2870b8517 #Generate a new image b532...
[root@localhost ~]# docker images | grep nginx
nginx 1.20.1 b532c001cdda 7 seconds ago 133MB #Generate a new image b532...
nginx <none> c8d03f6b8b91 2 years ago 133MB
/netrainpublic/nginx latest 90c072ff69fd 4 years ago 287MB
# Save Mirror
[root@localhost ~]# docker save -o nginx:1.20.1
[root@localhost ~]# ll | grep nginx
-rw-------. 1 root root 137402368 8moon 20 09:38
[root@localhost ~]#
target aircraft
[vipsoft@kafka1host docker]# docker images | grep nginx
# Load the saved image
[vipsoft@kafka1host docker]# docker load -i /home/vipsoft/docker/
e81bff2725db: Loading layer [==================================================>] 72.52MB/72.52MB
6662554e871b: Loading layer [==================================================>] 64.8MB/64.8MB
4edd8832c8e8: Loading layer [==================================================>] 3.072kB/3.072kB
0dcd28129664: Loading layer [==================================================>] 4.096kB/4.096kB
8ffde58510c5: Loading layer [==================================================>] 3.584kB/3.584kB
91117a05975b: Loading layer [==================================================>] 7.168kB/7.168kB
dd6582995144: Loading layer [==================================================>] 19.97kB/19.97kB
Loaded image: nginx:1.20.1
[vipsoft@kafka1host docker]# docker images | grep nginx
nginx 1.20.1 b532c001cdda 22 minutes ago 133MB
# Run the Nginx image
[vipsoft@kafka1host docker]# docker run -d -p 80:80 --name nginx nginx:1.20.1
3d7e05768d372f8753882505313563be23fd594ad6bb2778fd49ff9cf47cecdb
[vipsoft@kafka1host docker]# docker ps -a | grep nginx
3d7e05768d37 nginx:1.20.1 "/docker-entrypoint...." 10 seconds ago Up 9 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp nginx
# View logs
[vipsoft@kafka1host docker]# docker logs --tail=100 -f nginx