Docker Quick Start series (1): Image concepts and related operations

Source: Internet
Author: User
Tags docker ps docker hub

Docker Quick Start series (1): Image concepts and related operations
What is Docker?

One of the first questions I encountered about docker is what can docker do? What is docker? Here, let's take a look at Baidu encyclopedia's brief introduction to docker:

Docker is an open-source application container engine that allows developers to package their applications and dependencies to a portable container and then publish them to any popular Linux machine, you can also achieve virtualization. Containers fully use the sandbox mechanism and do not have any interfaces (similar to iPhone apps) between them ). With almost no performance overhead, it is easy to run on machines and data centers. Most importantly, they do not rely on any language, framework, or systems.

We can see that Docker is a container engine, which can be virtualized. What is virtualization? In fact, virtualization is a way to manage resources. Let's take a look at several common virtualization methods:

1. Full Virtualization: virtualization of the underlying hardware. For example, VMware Workstation
2. Partial Virtualization: only virtual
3. Operating System-level virtualization: the kernel isolates processes by creating multiple virtual operating system instances.

The implementation method of Docker container virtualization is operating system-level virtual.

Three functional modules of Docker

1. Image 2. Container 3. Repository

This article mainly introduces the image.
A Docker image is similar to a virtual machine image. If you want to use a windows operating system on your mac, we usually use the following method to download a virtual machine management program, such as VirtualBox, and then download a windows Image. We open VirtualBox to load our windows image so that a windows Image can run on mac through a virtual machine. We will talk about loading a Docker image in a Docker container later.

Get Image

Just like the process of loading windows images in VirtualBox described above, but we do not need a virtual machine management tool here. Our Docker container has solved the requirement of the Virtual Machine management tool, what we need to do next is to get the image we need to run.

docker pull # docker pull NAME[:TAG]

First, let's take a look at this command: "docker pull ubuntu: 14.10", which is actually downloading the ubuntu system image in the remote repository, give it a TAG to help us clearly understand the functions and content of each image in the future, just like "14.10" here. If you have used Git (a version management tool, other blog articles are introduced to you. You will find that there is a familiar feeling that one of the three core functions of docker is the repository. The implementation form is similar to that of Git, here, docker pull downloads the corresponding image from the Docker Hub warehouse to the local place. The Docker Hub warehouse here is similar to Github, but the former stores the image and the latter stores the code. Similarly, docker can specify its own repository address as Git does.
Let's take a look at the output result of the above docker pull ubuntu: 14.10 command. In fact, we only download a system image. Why is there a successful display of 5 files? In fact, the docker repository implements image storage by layer. The combination of digits and letters in the first column represents the id of the layer. Why is it stored in this form? I think it is similar to the Incremental Backup concept of our DB. Saves unnecessary space waste and improves image backup and download efficiency.

View images

How can we find all the available images downloaded locally? Here I still use Git as an example. Just like how does Git view local branches?

docker images 


From left to right, let's see what these fields mean:
Repository: The repository from, such as the ubuntu repository.
Tag: The tag information of the image.
Image id: the unique id of the image.
Created: Creation Time
Virtual size: Image size
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwPjxjb2RlIGNsYXNzPQ = "language-python hljs"> Tag: used to mark different images in the same repository. You can also manually Add Tag tags to the local images.

We can see that there is an extra job1 image with the same image id. In fact, they point to the same image file, but the alias is different.

Search and delete images
docker search


Let's see what these optional parameters mean.

1.--automated = false: Only automatically created image files are displayed.
2.---no-trunc = false: the output information is not truncated.
3.-s,--stars = 0: create an image that only displays the rating of a specified star or higher


The descriptions of fields from left to right are: name, description, star level, whether it is officially created, and whether it is automatically created. The star level indicates the degree of popularity. The higher the star level, the more popular it is.

Delete an image
Docker rmi NAME [: TAG] # delete an image


Here we deleted the newly created job1: fitest, but we can see that the deleted image file still exists. We just deleted a TAG. The image file is not deleted. If the image file only has one tag, run the docker rmi command again.
The image file will be deleted.

You can also delete an image. The iamge id is used to delete the image file. This operation deletes all tags marked on the corresponding image. If the deleted image is running in the container, the image cannot be deleted, however, you can use the command docker rmi-f to forcibly delete an image. It is not recommended that you delete an image in this way, because there will be some issues in the future (the official did not say anything about the impact ), the official step forward is to first Delete the container dependent on the image and then delete the image.

Docker ps-a # display all containers docker rm CONTAINER_ID # Delete the specified container
Create an image

There are three ways to create an image:
1. Create a container based on an existing image
2. Import based on local templates
3. Create Based on Dockerfile

Create an image based on an existing image container

docker commit [options] container [repository[:tag]]

-A:--author = "" author information-m:-message = "" submit information (similar to Git, git commit-m 'test')-p: --pause = true: temporarily stop the container upon submission


Here, 7868e765e7d is the id of the container. The image comparison between the container and ubuntu: 14.04has been changed. We created a 1.txt file in the image.
The license file is not added to the ubuntu: 14.04 image, but written in the coprocessor layer. Next we will submit the changes (which is too similar to Git ). Now let's take a look at the current image file:

Import based on local templates

cat ubuntu-14.04.tar.gz | docker import - ubuntu:14.04

Export and Import images
Docker sava # export image etc: docker save-o ubuntu_14.04.tar ubuntu: 14.04 docker load # Import image etc: docker load -- input ubuntu_14.04.tar or docker load <ubuntu_14.04.tar # note that the import here guides you into the local image list.
Upload the image to the repository
 docker push NAME[:TAG]

If you are using the default remote repository (DockerHub), you need to register an account in DockerHub, on which you can set whether the image in your repository is private.

docker push ubuntu:14.04

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.