Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create, save, and load Docker images

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to create, save and load Docker images. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Create based on an existing mirrored container

This method uses the docker commit command, which has the following command format:

Docker commit [OPTIONS] CONTAINER [REPOSITORY [: TAG]]

The main parameter options include:

-a,-author= "" author information

-mmam copyright message= "" submit information

-pmaxiausetrue submission is to suspend container operation.

For example, first create a ubuntu container that runs bash:

Docker run-it ubuntu / bin/bashroot@d8990fec2141:/# touch testroot@d8990fec2141:/# exit

Then submit a new image based on the container you created, using the container ID.

Docker commit-m "test"-a "zmc" d8990fec2141 testimage

If successful, the long ID number of the new image will be returned, and then you can check the existing images locally:

Docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEtestimage latest baea98d5a437 About a minute ago 188.3 MB.

The third line is the image you just created.

PS: the image Id created by this container is different from the image id of this container, so they are not the same image.

Import based on local template

You can also import an image from the operating system template file, such as using the template provided by OpenVZ. The OPENVZ download template can be found at: http://openvz.org/Download/template/precreated.

I tried to use the template of Ubuntu14.04:

Wget http://download.openvz.org/template/precreated/ubuntu-14.04-x86_64-minimal.tar.gz

After downloading, you can import:

Sudo cat ubuntu-14.04-x86_64-minimal.tar.gz | docker import-ubuntu:14.04

In fact, there are only two orders, but it is obvious that there is no need to explain. If successful, the long ID of the image created based on the template will be returned

Sudo cat ubuntu-14.04-x86_64-minimal.tar.gz | docker import-ubuntu:14.04ab80404d13d580965b9919b640169ccb585ea7884e6aa9de1ec043075c65fe35

Then you can view the local image:

Docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu 14.04 ab80404d13d5 56 seconds ago 215.4 MBtestimage latest baea98d5a437 29 minutes ago 188.3 MB … .

In fact, we can see that although the template is only 75m, the image created is not small.

Check-out and loading of images

You can use the docker save and docker commands to save and load images.

Save out mirror image

If you want to save the image to a local file, you can use the docker save command, for example, to save the local testimage:lastest you just created as the image file testimage.tar file:

Docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEtestimage latest baea98d5a437 25 minutes ago 188.3 MBubuntu latest fa81ed084842 3 days ago 188.3 MB … .docker save-o / data/testimage.tar testimage:latest

Line 6 above is to save out the code, and then there is a testimage.tar file under / data. Then we remove the local image rmi and try to load it.

Load Mirror

Status after deleting the mirror:

Ubuntu@VM-223-238 docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu ubuntu ab80404d13d5 5 minutes ago 215.4 MB $docker rmi baea98d5a437Untagged: testimage:latestDeleted: baea98d5a4371a6abf9efc8c53a54a6fc5befd167bf91ce9fd4a28a6d1b7dc5bubuntu@VM-223-238 Mercury ubuntu testimage:latestDeleted

Then load the image:

Docker load-input testimage.tardocker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu 14.04 ab80404d13d5 6 minutes ago 215.4 MBtestimage latest baea98d5a437 35 minutes ago 188.3 MB

The first line is to load the image, which can also be simplified to:

Docker load-input testimage.tardocker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu 14.04 ab80404d13d5 6 minutes ago 215.4 MBtestimage latest baea98d5a437 35 minutes ago 188.3 MB

The load operation will import the image and related metadata information (including tags, etc.).

Upload of image

Finally, let's talk about the upload of images. The management of images is very similar to that of git. You can use the docker push command to upload your local images to the repository. By default, you can upload them to the official DockerHub repository (login is required). Command format:

Docker push NAME [: TAG]

You usually add a tag with your own name (author information) to your image before uploading:

Docker tag testimage:lastest zmc/testimage:lastestdocker pushzmc/testimage:lastest

It is good for the distinction after uploading.

I think whether it is the operation and maintenance team, the development team or a laboratory, it is necessary to have their own Docker warehouse, which can store the environment or system images that meet their own needs, and can achieve rapid deployment.

This is the end of the article on "how to create, save and load Docker images". I hope the above content can be of some help to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report