Guide |
As one of the three core concepts of Docker, Docker image is a read-only template for the Docker engine that contains the file system. In fact, each Docker image contains a separate operating environment, such as a single image containing the CentOS OS environment, which we call a CentOS image. |
Before Docker runs a container instance, it can be a mirror-based environment, such as a Docker image with a CentOS operating system as a template. Before the container is established, Docker checks to see if there is a corresponding mirror locally, and if the mirror does not exist locally, Docker tries to get from the default Mirror warehouse (Repository, which is usually the default for the warehouse in the Docker hub public registry server. Users can configure custom image warehouses based on their specific environment and needs.
The related operations and commands for mirroring are described below.
View image Information
View the local mirror list
The Docker Images command can view a list of mirrors that are already on the local host, including the source repository, tags, ID, creation time, and image size.
View specific information for mirroring
The Dpcler inspect ID can get the details of the image, and after execution gets a JSON-formatted message that can be specified using the- F parameter if only one of the image's information needs to be queried. For example, get the author information for the Mirror:
$sudo Docker inspect-f {{". Author "}} [image_id]
Add a custom label to the image
Docker tag allows you to specify a label for the image to be customized (which is typically used for semantics), in effect adding a "shortcut" to an image.
Search Image
The Docker Search command searches the public and private mirrors in the remote mirror repository by default to the Docker hub's official image warehouse, using the Docker searchterm.
The search command allows you to query the image's name, description, number of star, whether it is officially created, whether it is created automatically, and so on.
Get Mirror
The Docker pull command can download the image locally from the network. The command format is Docker pull Name[:tag](if you do not explicitly specify tag, the lastest label is selected by default).
Of course, if you need to download the image from a non-default mirror repository, you can also download the image through the Docker pull URL . Of course, if this URL points to a valid remote mirror.
Remove Mirror
The Docker RMI command is used to delete a local image, using the Docker rmi Image[images ...], where image can be a label or mirror ID. We mentioned earlier that the label is actually a "shortcut", so deleting the image from the tag removes the "shortcut" and removes the image from the local area by deleting the label when only one of the images is left.
If your image also has a running container instance, it cannot be removed through Docker RMI , and of course you can force the removal of an image through the- F parameter, but this is often unsafe. The correct approach is to remove the corresponding container through the Docker RM CONTAINER and then delete the image through the Docker RMI .
Creating Mirrors
In general, we can create a Docker image in three ways: the creation of a container based on an existing mirror, local template import, Dockerfile creation.
Create a mirror based on a container that already has mirrors
This method relies primarily on the Docker commit command, which is used for Docker commit [options] [Respository[:tag]], and the main options are:
Parameters |
option |
Description |
-A |
–author= "" |
Author information |
-M |
–message= "" |
Submit Information |
-P |
–pause=true |
Suspend container run on commit |
Get the container ID that you need to create the image through the Docker PS command by executing:
$sudo Docker commit-m "[MESSAGE]"-a "[AUTHOR]" [container_id] [image_name]
Local template Import Mirror
Docker Import creates an image from a packaged image file and typically behaves as a. tar.gz compressed package. For example, import an Ubuntu OS image to a local:
$sudo Cat ubuntu-15.04-x86_64.tar.gz | Docker import-ubuntu:15.04
dockerfile Creating Mirrors
Dockerfile is a text-formatted configuration file that is actually represented as a collection of commands that users can use to quickly create custom images by customizing batch processing commands. Dockerfile typically consists of four parts: base image information, maintainer information, mirror operation instructions, and container start-up directives. After you finish editing the Dockerfile file, create the image from the Docker build command, for example:
$sudo Docker build-t [tag_name] [Dockerfile_path]
save and load photographed image
Save Image:Docker save
$sudo Docker Save-o Ubuntu-15.04-x86_64.tar ubuntu:15.04
load photographed Image:Docker load
$sudo Docker load--input ubuntu-15.04-x86_64.tar# or $sudo docker load < Ubuntu-15.04-x86_64.tar
Upload Image
The Docker push command can upload a mirror to a remote repository (the default is the Dockerhub official warehouse, which requires an account registration). Use as:Docker push Name[:tag], it is strongly recommended to add a good semantic tag name after uploading.
Summary
Mirroring is the premise of opening Docker containers, mastering the concept of mirroring and the corresponding view, get, search, delete, create, import and export, upload and other operations for Docker's introductory learning is of great help. We can also learn and use the more comprehensive image services offered by mirrored warehouses such as the Docker hub, such as the Web Query system (http://index.docker.io/), and we can share the high-quality mirrored resources we use daily with the open source community to learn together.
Free to provide the latest Linux technology tutorials Books, for open-source technology enthusiasts to do more and better: http://www.linuxprobe.com/
Docker Big Line-mirror