5. Use of Docker image

The image acts as a template for the container, and it cannot run without the image container. In Java object-oriented, there are classes and objects. Objects are instantiated by classes, and images and containers have a similar relationship.

 

1. Check the mirror list

You can view all local images through docker images:

List description: REPOSITORY: Repository source representing the image; TAG: Image tag; IMAGE ID: Image ID; CREATED: Image creation time; SIZE: Image size

The same repository source can have multiple TAGs, representing different versions of the repository source. As shown in the figure above, there are two images, both of which are tomcat, but the TAGs are 7 and latest, which represent the latest version of tomcat of tomcat7.

At the same time, use REPOSITORY:TAG to define different images. For example, if I want to start tomcat7, then specify tomcat:7 to start, otherwise specify tomcat:lastest to start:

If the specified startup image version does not exist, it will be downloaded from the docker image repository. By default, it will be downloaded from the Docker Hub public image source:

 

2. Start multiple containers by mirroring

Images and containers are like classes and instances, and every time a container is started from an image, it is a brand new container:

 

3. Find mirrors

We can search for images with the docker search command, assuming we need tomcat:

The searched image, we can download to the local through the docker pull image name, and the downloaded version is the latest!

If you do not want to pull the latest version, you can go to the Docker Hub URL: https://hub.docker.com/ to search for the image, it is easy to find the version information of tomcat, and finally download it locally through docker pull tomcat: version number (described in the previous article).

Column name description: NAME: the name of the mirror warehouse source; DESCRIPTION: the description of the mirror; OFFICIAL: whether docker is officially released

 

4. Download/Pull Mirror

We can use docker pull to pull or download the image locally. If the image is not downloaded locally, when the container is started through the image, since the image does not exist locally, it will automatically download the image and then start the container:

 

5. Create a mirror***

There are two ways to create an image, one is to use dockerfile to create a brand new image, and the other is to create an image by submitting it on the basis of the original image.

There are chapters in the dockerfile to create the image in detail. The following is to submit on the original image.

When the image we downloaded from the docker image repository does not meet our needs, we can integrate the tools from the already created container and submit it as a new image:

Requirement: Integrate lua based on the image of tomcat:7

①. View the mirrors we have

②. Start the container based on the tomcat image with TAG of 7

③. Enter the only-tomcat container interactive mode

Here, we enter the lua interactive mode and determine that lua has not yet been integrated. Now we are going to integrate lua on the basis of the container, and then submit it as a new image

④. Install lua in the only-tomcat container (note: it must be done in container interactive mode, because it is to be integrated into the container)

apt-get update -y && apt-get install -y luajit luarocks

⑤. Use the exit command to exit the container interactive mode and commit to a new image

⑥. Start a container with the new image lua and operate lua

 

6. Update the mirror

Updating an image is a bit similar to creating an image (a non-dockerfile-created image):

①. First start a container according to the image (still start the container according to the image of tomcat: 7)

②. Enter the container interactive mode, use the apt-get update command to update the running container, and after completing the operation, enter the exit command to exit the container:

③. At this time, the container whose ID is 595aae3418a3 is the container that has been changed according to our needs. We can commit the container copy by commanding docker commit:

Command description: -m: submitted description information; -a: specify the image author; 595aae3418a3: container ID; newimage:v1.1.1: specify the target image name and TAG version number to be created

 

7. Set the mirror tag

We can use the docker tag command to add a tag (TAG version) to the image. After adding, an identical image will be generated, even the image id is the same, but the version is different:

 

8. Delete the mirror

Use docker rmi to delete images. It should be noted that if the image to be deleted is associated with a container (regardless of whether the container is started or not), the image cannot be deleted:

First, look at the local mirror:

Second, start a container based on the lua image:

Next, we delete the lua image and see the result:

Next, we close the container and try to delete the image, but it still cannot be deleted:

Finally, we first delete the container associated with it, then try to delete the image, and finally delete:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324750728&siteId=291194637