There are three ways to create an image: creating a container based on an existing image, importing it from a local template, and creating it based on a Dockerfile. This blog post explains the first two. Creating a container based on an existing image The method is to use the docker commit command, the command format is: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] The main parameter options include:
For example, first create an ubuntu container running bash: docker run –it ubuntu /bin/bash root@d8990fec2141:/# touch test root@d8990fec2141:/# exit Then submit a new image based on the created container, and the container ID is required for submission. 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 images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE testimage latest baea98d5a437 About a minute ago 188.3 MB … The third line is the image just created. PS: The image ID created using this container is different from the image ID of this container, so it can be seen that they are not the same image. Import based on local template You can also import an image from an operating system template file, such as using the template provided by OpenVZ. The OPENVZ download template is at: http://openvz.org/Download/template/precreated. I tried using the template for Ubuntu 14.04: wget http://download.openvz.org/template/precreated/ubuntu-14.04-x86_64-minimal.tar.gz After downloading, you can import it: sudo cat ubuntu–14.04–x86_64–minimal.tar.gz | docker import – ubuntu:14.04 There are only two commands, but they are so obvious that I won't explain them. If successful, it will return the long ID of the image created based on the template sudo cat ubuntu–14.04–x86_64–minimal.tar.gz | docker import – ubuntu:14.04 ab80404d13d580965b9919b640169ccb585ea7884e6aa9de1ec043075c65fe35 Then you can view the local image: docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu 14.04 ab80404d13d5 56 seconds ago 215.4 MB testimage latest baea98d5a437 29 minutes ago 188.3 MB …. In fact, it can be seen that although the template is only 75M, the created image is not small. Image saving and loading You can use the docker save and docker commands to save and load images. Save the image If you want to save the image to a local file, you can use the docker save command. For example, save the local testimage:lastest file you just created as the image file testimage.tar: docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE testimage latest baea98d5a437 25 minutes ago 188.3 MB ubuntu latest fa81ed084842 3 days ago 188.3 MB …. docker save –o /data/testimage.tar testimage:latest The sixth line above is to save the code. At this time, there is a testimage.tar file under /data. At this time, we rmi the local image and try to load it. Loading the image Status after deleting the image: ubuntu@VM–223–238–ubuntu:/data$ docker rmi baea98d5a437 Untagged: testimage:latest Deleted: baea98d5a4371a6abf9efc8c53a54a6fc5befd167bf91ce9fd4a28a6d1b7dc5b ubuntu@VM–223–238–ubuntu:/data$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu 14.04 ab80404d13d5 5 minutes ago 215.4 MB Then load the image: docker load --input testimage.tar docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu 14.04 ab80404d13d5 6 minutes ago 215.4 MB testimage latest baea98d5a437 35 minutes ago 188.3 MB The first line is to load the image, which can be simplified as follows: docker load --input testimage.tar docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu 14.04 ab80404d13d5 6 minutes ago 215.4 MB testimage latest baea98d5a437 35 minutes ago 188.3 MB The loading operation will import the image and related metadata information (including tags, etc.). Image upload Finally, let's talk about uploading images. The image management method is very similar to git. You can use the docker push command to upload your local image to the warehouse. By default, it is uploaded to the DockerHub official warehouse (login required). The command format is: docker push NAME[:TAG] Before uploading, you usually add a tag with your name (author information) to your image: docker tag testimage:lastest zmc/testimage:lastest docker pushzmc/testimage:lastest It is helpful to distinguish after uploading. I think whether it is an operation and maintenance team, a development team or a laboratory, it is necessary to have its own Docker repository to store the environment or system images that meet your needs and achieve rapid deployment. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of unique constraints and NULL in MySQL
>>: Native Js implementation of calendar widget
I recently came into contact with MySQL. Yesterda...
Multi-way search tree Height of a complete binary...
This article example shares the specific code of ...
Follow the steps below 1. request.js content: htt...
Big data continues to heat up, and if you are not...
This article shares the specific code for impleme...
Table of contents 1 Problems encountered in trans...
How to use css variables in JS Use the :export ke...
Error: Connection to blog0@localhost failed. [080...
Table of contents background Understanding compos...
I was playing with CentOS in a VMware virtual mac...
Table of contents Event-driven and publish-subscr...
Preface A requirement I had previously made, to s...
Table of contents Preface 1. Linux changes the yu...
Table of contents Understanding Prototypes Unders...