Docker basis of practice 1 - Docker Introduction and Quick Start Experience

As the basis for this article series Docker first article will elaborate on and analyze three questions: What Docker that? Why Docker? How to quickly master the Docker technology?
This series of articles in Docker usage demo is based on CentOS7 carried out, it is assumed that the reader has mastered the preliminary knowledge of Linux, if you used commands operate on the basic Linux not familiar with, please refer to my previous write Linux Getting Started tutorial series .

A, Docker what
a simple sentence Profile: Docker is a kind of container virtualization technology.
To understand why Docker occur, it addresses what kind of problems, you should review the development process under virtualization technology and Docker's.

1.1 virtualization technology and classification
ps: If you believe we used to install or virtual machine VMware, perhaps you have experienced problems with virtualization technology. As my Linux introductory series of articles in the "Getting Started Series 1 linux and linux environment ready to install" mentioned in 3.2.1, you may encounter "This host this point Interl VT-x, but Interl VT-x is disabled state "this issue, if you want to install Linux in VMware, it should be open virtualization support in the BIOS.

Virtualization technology is a generic concept, different areas may have different interpretations. In the computer field generally refers to computing virtualization or server virtualization, which is the core abstraction of resources to be able to run multiple systems or software applications as the goal, to increase the utilization of system resources while the server on the same host rate, reduce costs and facilitate the application life cycle management.
Divided into two general categories virtualization technology Category: hardware-based virtualization and virtualization-based software.
The true sense of hardware-based virtualization rare, and software-based virtualization from the level of the object is located, can be divided into virtualization and application virtualization platform. Application virtualization refers generally refers to virtual technology to simulate the device through software, we usually refer most cases, virtualization technology platform.
Platform virtualization can be broken down into the following categories:

  • Fully virtualized
    VM-simulated environment of the underlying hardware and privileges of refers to the implementation process, the guest operating system need not be modified. For example: VirtualBox, VMware Workstation
  • Hardware-assisted virtualization
    with hardware main function is to assist the CPU support handle sensitive instructions to implement fully virtualized guest operating systems without modification. Currently available on 86 architecture hardware-assisted virtualization technologies including Intel-VT and AMD-V. For example: VMware Workstation, Xen, KVM
  • Part of virtualization
    only for part of the hardware resources virtualized guest operating systems need to be modified.
  • Paravirtualization
    some hardware interfaces provided in the form of software to the client operating system, the guest operating system needs to be modified.
  • OS-level virtualization
    kernel to isolate different processes by creating multiple virtual operating system instances (including the kernel and libraries). We usually refer to container-related technology belong to this category, and it is one of these many Docker container technology.

If you say the relationship between the Docker and virtualization technology, I think it can be summarized as: virtualization technology through the development of the past to achieve virtualization of the traditional way through from the hardware level, and gradually evolved into today's popular operating system based on the level of the container of the way. Docker container and the leader of the art as stand.

Past and Present 1.2 Docker
Docker container is based on open source projects Go language implementation, Docker project has joined the Linux Foundation, and follow the Apache agreement, all open source projects are maintained in https://github.com/docker warehouse.
As the official website said, the idea Docker is "Build Ship and Run Any App, Anywhere", that is, through the application package (Packaging), distribution (Distribution), deployment (Deployment), running (Runtime) lifecycle management, It simply is a package, run everywhere.
Docker is currently supported by the major mainstream operating system, including the major Linux distributions, Windows, MacOS, etc. can be installed. While the major cloud service providers such as IBM, Amazon, Azure and other cloud platforms provide integrated support for Docker's.
Why then Docker will develop so rapidly it?
As Docker founder said, Docker just at the right time and the right place doing the right thing, it's no accident occurs, it is actually developed from standing on the shoulders of our predecessors LXC. LXC (Linux Containers) that is usually said Linux container technology LXC for more details do not say, simply is LXC over a long period of development, stepped on a lot of the pit, and then be integrated into the mainstream Linux content, the positive so that it is paving the way for the early birth of Docker's.
Docker LXC on the basis of further optimize the experience of the container, the container technology makes universal. For example, it offers a variety of tools to achieve distribution container management, version transplant application, so that users do not need to focus on the underlying operating; also introduces a hierarchical file system and efficient mirror mechanism, greatly reducing the difficulty of migration. Early Docker is directly based on the LXC, after the 0.9 version developed libcon-tainer project as a drive to achieve a wider container, which replaced the realization of LXC, trying to get support vessel is no longer confined to the Linux operating system, but more security, more open and more scalable.
It is based on a number of open source technologies on the Linux platform, Docker provides an efficient, agile and lightweight container program, and to support the deployment of the local environment and a variety of mainstream cloud platform. Docker can be said for the first time in application development, deployment and operation provides a "one-stop" practical solutions.

1.3 Docker core concepts
Docker contains three core concepts: Mirror, containers, warehouses, part of the basis functions are deployed around them, so there is a simple first impression can be.

  • Mirroring
    can be simply understood as a package or a read-only template applications and their environment, behind the container is to be created by it. It is similar to a virtual machine image, if you have experience in object-oriented programming, it can also be understood as an entity class (Class).
  • Container
    simply understood as a sandbox, isolated and used to run applications we develop. You can be understood as a virtual machine is running, it can also be understood as an object created by the entity class Clss. Mirroring is static, the container is dynamic.
  • Warehouse
    Warehouse is the integration of local storage mirroring, Docker warehouse similar to the code repository, if you have experience with Git and Maven, it would be well understood.
    Official repository for the Docker Hub, but sometimes overseas speeds less than ideal, so domestic manufacturers such as Ali cloud cloud cloud Netease, also provides a local mirror in warehouses, of course, can build their own private warehouse.

Second, why should Docker
to figure out why we use Docker, then take a look at what some of Docker are competent?

2.1 Docker rapid deployment and development
as the Declaration on the concept of Docker's: one package, run everywhere. Since Docker image is to package together we develop applications needed to run and his environment, its benefits are obvious, especially the rapid deployment and distribution capabilities.
Here is a simple example, suppose we have previously developed a software deployed on a single server, but for whatever reason, we want to deploy the software on another server. Under normal circumstances we need to how to do it? We need to log on to the new server, according to the previous procedure was repeated once deployed operating environment, and then run the observations, but also that with unknown effects of changes in the environment. That is if Docker what will happen? We just need to download the appropriate image then can be up and running. Fast and peace of mind.
Remember LNMP environment in front of a series of articles to build it? "Linux entry of the series 20-Web services architecture LNMP combat", is not feeling much trouble? This process less have half an hour, if we replaced Docker deployed, then it can handle every minute. Later will demonstrate the use of Docker way to deploy LNMP, that time there will be a very visual contrast, I believe you will fall in love with Docker.

2.2 Docker DevOps advantage of
using Docker package can be done once, run everywhere.
Because the mirror already contains the environment, it does not exist locally developed to run developers no problem, but the situation there to run the operation and maintenance personnel issues. At the same time it makes the migration, expansion and update management easier, greatly reducing the duplication of effort, effectively the liberation of the operation and maintenance personnel.

2.3 Docker contrast with the virtual machine
container virtual machine technology in performance win.
In addition to applications running Docker containers therein, substantially consumes additional system resources to ensure application performance while minimizing system overhead.
N traditional virtual machine run different applications will enable the N virtual machines, each virtual machine needs to allocate exclusive memory, disk and other resources alone, while Docker just need to start N containers, and applications into a container that is can.
It's startup speed, performance, memory costs, mobility and so win virtual machine.

2.4 Docker applications in micro-service
micro-services architecture is one of the hot technology of the current development in the field of software, if you're a developer or understand the development of technology, I believe you must have heard monomer applications and services that micro two terms.
In the course of the evolution of software architecture, once a filing package (such as war package) that contains all the functionality of the application, such as a Web system we all functional blocks are put together, usually called monomers applications. Although you may be modular in-house development projects, but all business functions are included in a project, such complexity is high, the deployment of trouble, poor reliability. For example, only a small modification which functions have to redeploy; in which a small part of the problem will cause the entire system problems.
To address these situations, and thus a micro-service architecture. If you are a Java developer, it mainly refers to the Spring Boot and Spring Cloud technology stack. Micro-service function is required to split a single business, the split reliable complex systems for each small module, although it has many advantages, but it also increases the difficulty of operation and maintenance and management.
Although micro Services Architecture Once the container is a lot of time to manage a little trouble, but Docker can be well managed for each vessel, elastic expansion, etc., and therefore tend to adopt SpringBoot + SpringCloud + Docker micro-service architecture model.

2.5 Docker in BigData application of
the traditional big data architectures are often deploy Hadoop, Hbase, Kafka, Zookeeper, Flink, Spark , and so the cluster, if both manually or using a script to manage the efficiency is very low, and to deal with elastic expansion or volume reduction, migration scenario is also control additional work needs to be done, and if Docker deployment and management of container, all this will become easier.
This part of the presentation will follow after the completion of large data sharing knowledge in return to compare, so stay tuned.

2.6 Docker applications in major companies in the
Docker container technology and has been fully validated in major companies, such as: Jingdong 618, the US group comments, Tencent, Sina, mushrooms street and so on.

  • Docker application in Jingdong 618
    2016 Jingdong elastic cloud team, Docker from 10,000 to 150,000, from the application to take full part to test the water flow through a rigorous test of 618.
  • Application Docker in the US group review in
    2015, the US group cloud team began to test the water Docker container cluster management platform, optimized and perfected a number of columns, before the platform for the US group reviews, the hotel take-away, to shop, cat's eye, more than 10 several Division computing services to provide a container, carrying hundreds of online business, a service type covers the Web, databases, buffers, message queues and the like.
  • Docker in the application Tencent
    Tencent Docker formally launched in October 2014, based on code-named Gaia Yarn scheduling platform compatible and non-Docker Docker type of application, including its parent business offline, real-time online service as well as services such as Hadoop MR , Spark, Storm, Hive and internal Tencent Lhotse, Hermes, wide-point and other services.
  • Docker Sina microblogging application
    DCP Weibo is based Docker hybrid cloud architecture, in 2014 made a Docker container of 2015 made private cloud and hybrid cloud + also dynamic scheduling, calmly deal in 2016 one billion PV, one hundred billion data, the size of more than 2,000 servers and more than 20 service module size, ten billion Hbase data storage, more than thousand units Docker hybrid cloud cluster.
  • Docker in the application mushroom Street
    line items mushroom cloud private street on the 2014 Christmas period, the application is split into a micro-services, and PaaS based application deployment and publishing. Experienced several double 11 big promotion, it has gradually formed a certain scale.

Three, Docker how to use
3.1-related sites
official website
https://www.docker.com/
can see Docker into Community Edition (CE) and Enterprise Edition (EE) from the official website, you can use the Community Edition under normal circumstances.

Online Docker practice
https://labs.play-with-docker.com/
the site is to help people learn captain Docker Docker and spent a few days to develop a product, play-with-docker browser-based, person PWD, it is a testing ground of a Docker.
It allows users to run Docker command within a few seconds, you can build, run Docker containers can even create a cluster in Docker Swarm mode, also contains a large number of Docker labs and test examples.
Users can experience free of Alpine Linux virtual machine in the browser, where the user can build, run Docker containers can even create a cluster in Docker Swarm mode. In addition to the training ground, PWD also contains a large number of labs and tested by example Docker.
If you just want to quickly experience the Docker, you do not even have the local environment can be installed immediately experience, register an account or directly Docker Hub account to log into the experience.

3.2 Docker installed
As mentioned earlier support for Linux, Windows, MacOS, etc., but the production environment, we generally use in Linux, this article will demonstrate the installation and use Centos7 at Docker's.
Docker's installation is very simple, just follow the prompts official website.
Rpm, yum, scripted: official website describes the three methods of installation have
the following installed using YUM way

3.2.1 Preparing Virtual Machines
configured IP address, and in order to reduce interference, turn off the firewall and SELinux.
If your system requires relatively old yum update it, this step is not necessary.

[root@docker ~]# yum update -y

3.2.2 install the necessary packages

[root@docker ~]# yum install -y yum-utils \ device-mapper-persistent-data \ lvm2
...省略部分输出内容
Complete!
[root@docker ~]#

3.2.3 Setting warehouse

[root@docker ~]# yum-config-manager  --add-repo https://download.docker.com/linux/centos/docker-ce.repo
...省略部分输出内容
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@docker ~]#

Here the direct use of official repository https://download.docker.com/linux/centos/docker-ce.repo, if you Suman can be replaced by domestic warehouse, such as Ali cloud.

3.2.4 Installation Docker

[root@docker ~]# yum install docker-ce
...省略部分输出内容
Complete!
[root@docker ~]#

The installation process by three times to confirm y. This process with speed, generally more than 10 minutes to complete the installation.
In the absence of concrete with a version number after the order, so the default tag for the lastest, so there is time to execute different versions may be different, the production environment is recommended to bring the version number specified.

3.2.5 Docker start
after the installation is complete Docker is not enabled, so you need to start Docker, and set to boot. Docker can be viewed by systemctl status docker state.

[root@docker ~]# systemctl start docker
[root@docker ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@docker ~]# systemctl status docker
  docker.service - Docker Application Container Engine
  Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
  Active: active (running) since Wed 2020-02-26 21:39:22 CST; 1min 30s ago
    Docs: https://docs.docker.com
Main PID: 57003 (dockerd)
  CGroup: /system.slice/docker.service
...省略部分内容

It can be seen in the running state, thus docker install and start successfully.

View version 3.2.6 Docker information and
view version information

[root@docker ~]# docker -v
Docker version 19.03.6, build 369ce74a3c

View docker installation information

[root@docker ~]# docker info
...省略部分内容
Docker Root Dir: /var/lib/docker
...省略部分内容

You can see the default installation path / var / lib / docker.

3.3 Running the first container
3.3.1 to create the first vessel
after our ready-hello-world image provided by the official Docker Hub to create a container, the container is created using the docker run command function it is to create the container and start output helloworld words.

[root@docker ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:fc6a51919cfeb2e6763f62b6d9e8815acbf7cd2e476ea353743570610737b752
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
   (amd64)
3. The Docker daemon created a new container from that image which runs the
   executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
   to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

[root@docker ~]#

We can see the successful operation of the vessel, and the output of hello from docker!
At this time, the local use of docker images command to view mirror, the mirror can be seen that the called hello-world.

[root@docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        14 months ago       1.84kB
[root@docker ~]#

3.3.2 helloworld container principle analysis
runs a container, inside the container is actually running the program, as we usually do helloworld program, we need to develop with java or any other language, then packaged as a jar file, and then through the java command carried out. Every time you need to run the program needs to be done manually execute the command, and in the docker, we put helloworld corresponding jar package packed into a container, the container only needs to run, the program can be executed immediately, it is not very convenient?
We analyze the principle hello-world container operation: First, we see "Unable to find image 'hello- world: latest' locally" this prompt, indicating that no local hello-world image, he will automatically go to the warehouse from Docker Hub download the image, and then create the container and run the helloworld program within the container, this process is automated done.
And the start of this container is in fact equivalent to a small linux system, but start very fast, a few seconds up and running, which is the previously mentioned advantages and virtual machines compared.
As for why so fast? And that what is in the container? What docker commands can be executed? In a subsequent article, you will find the answer.

Such Docker environment is ready, start the next article, we demonstrate the use of formal methods to Docker in various commands.

Original articles published 0 · won praise 0 · Views 584

Guess you like

Origin blog.csdn.net/qq_41490913/article/details/105026670