Three docker components: Image and docker

Source: Internet
Author: User
Tags gz file docker cp docker hub

Three docker components: Image and docker
1. Images of Docker's three major components.

A corresponding image must exist locally before Docker runs the container. If the image does not exist locally, Docker downloads the image from the image repository (default is
Docker Hub Public Registry server warehouse ).

Obtain images from the repository, manage images on the local host, and introduce the basic principles of image implementation. 1.1 get docker pull command

We downloaded an image of the Ubuntu 12.04 operating system from the Docker Hub repository.

# As mentioned in the previous blog, obtain an image. [Root @ bfd-v7 ~] # Docker pull ubuntu: 12.04
1.2 list all images and docker images commands
docker images

In the list information, you can see several field information:

From which warehouse, such as the ubuntu Image Tag, such as 14.04 its ID (unique) Creation Time Image Size 1.3 Create Image

There are many ways to create an image. You can obtain and update an existing image from Docker Hub, or create

1.3.1 generate a new wyl-nginx Image Based on the existing nginx image.
docker cp index.html 5cbfdbbe064b://usr/share/nginx/htmldocker commit -m "fun" 5cbfdbbe064b wyl-nginx

The previous nginx image is the nginx welcome page of the running page. We make a modification to the previous image and then run it. Then a new image will be generated.

1.3.2. Use Dockerfile to generate an image
# Create a dl directory named dockerfile [root @ bfd-v7/] # mkdir dl [root @ bfd-v7 dl] # cd dl [root @ bfd-v7 dl] # touch Dockerfile [root @ bfd-v7 dl] # vim Dockerfile # Write the upper and lower vertices FROM alpine: latestMAINTAINER wyl9527CMD echo "hello docker"

The basic syntax of Dockerfile is:

Use # To comment out the FROM command to tell Docker which image is used as the basis, followed by the maintainer's information Command run by CMD
[root@bfd-v7 dl]# docker build -t hello-docker .

The-t tag is used to add tags to specify the user information of the new image. "." Is the path of Dockerfile (current directory). It can also be replaced with a specific Dockerfile path.

You can see that the build process is performing operations. The first thing it needs to do is upload the Dockerfile content, because all operations must be performed based on Dockerfile. Then, the command in Dockfile is executed one by one. Each step creates a new container, executes commands in the container, and submits modifications (just like docker commit ). After all the commands are executed, the final image id is returned. All containers generated by the intermediate steps are deleted and cleared.

* Note that an image cannot exceed 127 layers.

1.4 Export and Import images 1.4.1. To export images to a local file, run the docker save command.
[root@bfd-v7 ~]# docker save -o wyl-nginx.tar.gz wyl-nginx[root@bfd-v7 ~]# docker save -o hello-docker.tar.gz hello-docker

Export to the current directory, such as the hello-docker.tar.gz file.

1.4.2 you can use docker load to import data from the exported local file to the local image library.

Before deleting an image, use docker rm to delete all containers dependent on the image.
Since we already have a hello-docker image, we need to delete it before importing it.

[Root @ bfd-v7 ~] # Docker rmi hello-docker # the following error occurs

[Root @ bfd-v7 ~] # Docker load

1.5 remove a local image

To remove a local image, run the docker rmi command. Note that the docker rm command is to remove the container. Otherwise, an error is returned.

[Root @ bfd-v7 ~] # Docker rm container id # See the operation procedure in the preceding section. [Root @ bfd-v7 ~] # Docker rmi hello-docker

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: 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.