There are three ways to create a mirror: Created from a container based on an existing image, imported based on a local template, and created based on Dockerfile, this blog explains the first two.
Create a container based on an existing mirror
The method is to use the Docker commit command, whose command format is:
Docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
The main parameter options are:
- -A, –author= "" Author information
- -m,–message= "" Submit information
- -p,–pause=true commit is a halt container run
For example, first create an Ubuntu container that runs bash:
Docker run –it ubuntu /bin/bash root@d8990fec2141:/# Touch Test Root @d8990fec2141:/# exit
The container ID is then used to submit a new image based on the container you created.
Docker commit –m "test" –a "ZMC" d8990fec2141 testimage /c7>
If successful, the long ID number of the new image is returned, and you can see the image that is already in the local area:
Docker Images repository tag image id CREATED VIRTUAL < Span class= "crayon-e" >size testimage Latest baea98d5a437 about a minute ago 188.3 MB
......
The third line is the image you just created.
Import based on local template
You can also import a mirror from the operating system template file, such as using the template provided with OpenVZ, OpenVZ download the template in:http://openvz.org/Download/template/precreated.
I tried using the Ubuntu14.04 template:
1 |
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, it is only two orders, but it is obvious that it is not explained. If successful, it returns the long ID of the image created by the template
sudo cat ubuntu–14.04–x86_64–minimal. Tar. GZ | Docker Import – ubuntu:14.04 ab80404d13d580965b9919b640169ccb585ea7884e6aa9de1ec043075c65fe35
You can then 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 minutes ago 188.3 MB ....
As you can see, although the template is 75M, the image created is not small.
storage and onboarding of images
You can use the Docker save and Docker commands to save and load photographed images.
To save a mirror
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 that you just created as a mirrored file Testimage.tar file:
Docker Images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SI ZE 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 6th line above is to save the code, at this time there is a Testimage.tar file under/data, then we take the local image rmi off, and then try to load.
Load photographed like
Delete the status after mirroring:
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 photographed like this:
Docker Load -input testimage. Tar Docker Images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SI ZE ubuntu 14.04 ab80404d13d5 6 minutes ago 215.4 mb testimage Latest baea98d5a437 minutes ago 188.3 MB
The first line is the photographed image, which can also be simplified as:
Docker Load < testimage. Tar
Loading will import the image and related metadata information (including tags, etc.).
Upload of images
Finally say the image of the upload, the image is managed very much like git, you can use the Docker push command to upload your local image to the warehouse, the default upload to the Dockerhub official warehouse (need to login), command format:
Docker push NAME[:TAG]
Before uploading, you will typically add a tag with your own name (author information) for your image:
Docker tag testimage:Lastest zmc/testimage:Lastest Docker pushzmc/testimage:Lastest
Facilitates post-upload distinctions.
I think whether it's an OPS team or a development team or a lab, it's necessary to have a Docker repository of your own that can store the environment or system image that fits your needs, enabling rapid deployment.
Turn from: Dream Continuation code
Create, store, load, and Mount Docker images