Docker Basics Tutorial--Mirroring

Source: Internet
Author: User
Tags commit unique id docker hub

Source: http://blog.csdn.net/anxpp/article/details/52464806

The previous article also said that mirroring is one of the three core concepts of Docker.

Docker needs to have a corresponding mirror locally before running the container, and if it does not exist locally, it will attempt to get from the default (Docker Hub) mirror Warehouse, or you can configure a mirrored warehouse that uses custom. 1. Get the image

Mirroring is the basis of Docker, the premise of running containers.

You can use commands to download the image from the network, as follows (if not the root user needs to add the sudo command before the command):

Docker Pull Name[:tag]
If the specified tag is not displayed, the mirror download of the latest tag is selected by default.

For example, to download a new Ubuntu Image:

Docker pull Ubuntu
Here the actual download is the image of the latest tag, the above command is equivalent to:

Docker Pull Ubuntu:latest
The download process will see that the image file is actually composed of multiple layers, the first of each line is the ID of this layer.

Layer is an important concept in Aufs (a federated file system) and is the basis for implementing incremental saves on updates.

If you need to download a specific version of the image, you can:

Docker Pull ubuntu:14.04
If you want to download the image from the warehouse of the specified registered server, you can do the following:

Docker Pull Registry.hub.docker.com/ubuntu:latest
After the download is complete, you can start:

Docker-t-I. Ubuntu/bin/bash
The commands here will be explained later.

2. View image Information

The Docker image command lists all of the images that are already in the local area:

Docker Inages
The fields that are displayed are indicated separately:

1. from which warehouse

2, the image of the label information

3. Unique ID of the mirror

4. Creation time

5. Image size

Where the ID of the image is more important and is often used.

Tag tag is used to mark images of different versions of the same warehouse.

For ease of use, you can also add a new label to the local mirror via the docker tag command:

Docker tag Ubuntu:latest Ubuntu:newtag
At this point, the image list will be more than one mirror, but its ID is still the same.

Use the docker inspect command to get the details of the image:

Docker Inspecct Image ID
This returns a JSON-formatted string that can be specified by-F if you want to get only the content specified in it:

Docker inspect-f {{". Architecture "}} 550
This is the architecture information returned.

At any time, when specifying an ID, you can specify only the first few characters in place of the complete ID string, provided it is uniquely marked. 3. Find the image

The Docker Search command searches the public image in the remote repository, which defaults to the Docker hub warehouse.

To use:

Docker Search term
The supported parameters are as follows:

1 、--automated=false: Show only auto-created mirrors

2 、--no-trunc=false: Output information does not truncate display

3,-S,--stars=0: Specifies that only comments are displayed for images above the specified star rating

For example, to search for an image with the Lamp keyword:

Docker Search Lamp
The information returned later includes: image name, description, star rating, whether the official creation and whether it is created automatically, etc.

The default output is sorted by star rating, the official image description is created and maintained by the official project team, and the automated resource allows the user to verify the source and content of the image. 4. Remove the image

You can remove the image using the mirrored label and ID.
The command format is:

Docker RMI Image[image ...]
Image can be either a label or an ID.

When there are multiple labels for the same image, the Docker RMI command simply removes the labels specified in multiple tags of the mirror and does not affect the image file.

If the image is left with only one label, the use of the Docker RMI command will completely remove the image.

If the Docker RMI is followed by an ID deletion, it attempts to delete all the tags of the mirror after deleting the image file itself.

If the container that you are creating to delete the transports image exists, the image file is not deleted by default. If you execute the delete command directly, you will be prompted to have the container running (even if the container has already been exit). However, you can add the parameter-F to forcibly delete:

Docker rmi-f ID or label
However, this is not recommended, because this may lead to some legacy issues, if it is necessary to delete, it is recommended to remove all containers of the image, and then remove the mirror, if a container cannot be deleted, then this image should not be deleted directly.

When you delete a mirror, you output the same layer of information that is similar to getting the mirror. 5. Create Image

There are three ways to create an image:

1, based on the existing image created

2. Import based on local template

3, based on Dockerfile file creation

In the case of large-scale applications, the third approach is generally used, so there is no detail here (follow-up article will be detailed), here are the first two.

5.1. Create this method based on an existing image the main use of the Docker commit command, in the format:

Docker commit [OPTIONS] CONTAINER [Repository[:tag]]
Among the options:

-A 、--author= "": Author Info-m\--message= "": Submit Message-P 、--pause=true: Pause the container when committed.

Here is an example:

Docker commit-m "Message"-a "anxpp" container ID new container tag new container ID
You can then view the created container through the Docker images command.

5.2, based on local template import a mirror can be imported directly from an operating system template file. such as the template provided by OpenVZ (http://openvz.org/Download/templates/precreated)

For example, to import the downloaded Ubuntu template for mirroring:

Cat Ubuntu-14.04-x86_64-minimal.tar.gz | Docker import-ubuntu:14.04
You can then use Docker images to see the image.

6. Import and export of images (files)

There may be times when we want to export images directly as files for use elsewhere, and Docker provides such functionality. 6.1. Export image as File

Use the Docker Save command to save the image as a file, such as:

Docker Save-o Ubuntu.tar ubuntu:14.04
6.2. Import images from files

Use the Docker load command to import the file as a mirror, such as:

Docker Load < Ubuntu.tar
The image and related metadata information, such as tags, are imported at this time.

7, upload image upload image to the warehouse using the Docker push command, the default is uploaded to the Dockerhub official warehouse (login required), the command format is Docker push Name[:tag].


Summary Image is the premise of using Docker, while using the process can collect some more useful images, the current online popular image Warehouse has a large number of stable and good image, we can use it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.