Xiaobai’s Python crawler (4): preparation (3) introduction to docker

Time:2020-8-14

Xiaobai's Python crawler (4): preparation (3) introduction to docker

Life is short, I use python

Previous portal:

Xiaobai’s Python crawler (1): Opening

Python crawler (2): preparation (1) installation of basic class library

Learn Python crawler (3): preparation (2) introduction to Linux

Docker Foundation

First of all, just a day before the writing of this article, mirantis announced the acquisition of docker’s enterprise business and team. And on the official website also hang the relevant text.

Xiaobai's Python crawler (4): preparation (3) introduction to docker

Nothing else. Let me know the news.

Docker website address: https://www.docker.com/

What is docker?

Emmmmm, to tell you the truth, it’s not easy to tell what docker is. Let’s roughly explain what docker is through four points.

  1. Docker is the world’s leading software container platform.
  2. Docker is developed and implemented with go language introduced by Google company. Based on CGroup and namespace of Linux kernel and unionfs of aufs class, docker encapsulates and isolates processes, which belongs to virtualization technology at the operating system level.
  3. Because the isolated process is independent of the host and other isolated processes, it is also called container. The initial implementation of docke is based on LxC.
  4. Users can easily create and use containers and put their applications into containers.

Xiaobai's Python crawler (4): preparation (3) introduction to docker

Features of docker container:

  1. Lightweight: multiple docker containers running on a machine can share the operating system kernel of this machine; they can start quickly, and only need a small amount of computing and memory resources. Images are constructed through the file system layer and share some common files. This will minimize disk usage and download images faster.
  2. Standardization: the docker container is based on open standards and can run on all major Linux versions, Microsoft Windows and any infrastructure including VM, bare metal server and cloud.
  3. Security: the isolation that docker gives to applications is not limited to isolation from each other, but also independent of the underlying infrastructure. By default, docker provides the strongest isolation. Therefore, problems in the application are only the problems of a single container and will not affect the whole machine.

Why use docker

  • The docker image provides a complete runtime environment in addition to the kernel, which ensures the consistency of the application running environment, so that there will be no problem with this code on my machine again
  • It can be started in seconds or even milliseconds. It greatly saves the time of development, testing and deployment. ——Faster startup time
  • Avoid public servers, resources can be easily affected by other users. ——Isolation
  • Be good at dealing with the server usage pressure of centralized explosion
  • It is easy to migrate the application running on one platform to another platform without worrying about the situation that the application cannot run normally due to the change of running environment. ——Easy migration
  • With docker, continuous integration, continuous delivery and deployment can be realized by customizing application images. ——Continuous delivery and deployment

Speaking of container, the comparison with virtual machine is an eternal topic, because what it does is very close to that of virtual machine.

The traditional virtual machine technology is that after a set of hardware is virtualized, a complete operating system is run on it, and then the required application process is run on the system; while the application process in the container runs directly in the host kernel, there is no kernel in the container, and there is no hardware virtualization. Therefore, the container is more portable than traditional virtual machines.

Xiaobai's Python crawler (4): preparation (3) introduction to docker

Docker installation

Installation under win10

First, introduce the installation of docker in win environment. Open the official website and download the latest version of docker desktop.

Official download address of docker: https://www.docker.com/produc…

You may need to register the docker hub before downloading. After registration, you will jump to the download page directly.

Xiaobai's Python crawler (4): preparation (3) introduction to docker

After the download is completed, it is OK to configure next by default.

verification:

From the CMD command line, execute:

docker info

Please ensure that the docker is started normally, otherwise an error will be reported.

The local computer will display the following after execution:

Client:
 Debug Mode: false

Server:
 Containers: 26
  Running: 0
  Paused: 0
  Stopped: 26
 Images: 28
 Server Version: 19.03.1
 ...

If there are too many contents, I will not post them all. It will mainly display some information related to the current docker.

Installation under CentOS

The lazy artifact is installed by using the package management tool Yum under CentOS. You can directly input:

yum install docker

Then wait for the progress bar to finish, and verify that the command is consistent with the above. Also, ensure that the docker service is started normally.

Basic docker operation commands in CentOS:

#Docker start
systemctl start docker
#Restart the docker service
systemctl restart docker
#Shut down docker service
systemctl stop docker

Validation results:

Xiaobai's Python crawler (4): preparation (3) introduction to docker

Docker Foundation

First, understand two concepts

Image: the docker image is a template used to create a docker container.

Container: a container is an application or group of applications that run independently.

In other words, the image can be our own program, or it can be a component provided by a third-party manufacturer, such as database, cache service, and so on. If the image wants to run, it must be run in a container. It can’t run alone. It’s just like frying dishes. It can’t be done with only vegetables, but also with pots. The dishes are fried in the pot.

Xiaobai's Python crawler (4): preparation (3) introduction to docker

Since the default image source of docker is on the other side of the Pacific Ocean, the access speed will be slow. It is recommended that you configure a domestic image source.

There are many image sources in China. Baidu can find a lot of them. Xiaobian uses the container image acceleration service provided by Alibaba cloud here. You can log in to your Taobao account and find container image service on Alibaba cloud

Xiaobai's Python crawler (4): preparation (3) introduction to docker

The specific configuration scheme has been provided by alicloud. I won’t repeat it here. Please log in to Alibaba cloud to check it.

After all the above configurations are completed, let’s talk about some of the most basic docker commands:

Get image

Syntax: docker pull name [: tag]
Where name is the name of the image warehouse (used to distinguish images), and tag is the label of the image (used to indicate version information)

View image

Syntax: docker images

Xiaobai's Python crawler (4): preparation (3) introduction to docker

As you can see, there is a mysql5.7 image on the machine.

Search image

Syntax: docker search [image name]
Search docker image from docker warehouse

delete mirror

Syntax: docker RMI name
It is used to delete the specified image. The following parameter can be tag. If it is a tag, it is actually deleting the tag. As long as there are other tags in the image, the image will not be deleted. When the following parameter is the image ID, the entire image will be deleted completely, and all tags will be deleted together

Hello world

Enter first docker pull hello-world Come and get ithello-worldImage:

Xiaobai's Python crawler (4): preparation (3) introduction to docker

After the pull is successful, we use thedocker imagesTake a look at thishello-worldImage:

Xiaobai's Python crawler (4): preparation (3) introduction to docker

Well, we’ve seen thishello-worldMirror, now try to start, use the commanddocker run hello-world

Xiaobai's Python crawler (4): preparation (3) introduction to docker

If the content in the above figure appears, it indicates that hello world runs successfully. If it does not appear, emmmmmmmmmmmmm, you may have to think about your previous operation.

This article ends here. I hope you can practice it by yourself. After all, practice makes true knowledge.

reference resources

http://dockone.io/article/6051

Xiaobai's Python crawler (4): preparation (3) introduction to docker

If my article is helpful, please scan the code to pay attention to the official account of the author: get the latest dry cargo push: