This article will take you to understand docker technology

What is Docker

Docker is a virtual technology that was born in 2013. It is an open source project developed by dotCloud company. Because the company docker was later renamed docker inc, the goal of docker is to achieve lightweight operating system virtualization solutions. In layman's terms, if we want to run multiple systems on one machine, a virtual machine is created. When we want to run many virtual environments on one system, the virtual machine will not work. At this time, docker appears, and docker is based on Linux container technology has been encapsulated a lot, so users don’t have to worry about container management, making operations simpler. Users use docker containers just like using a fast and lightweight virtual machine, which is very simple and convenient.

There are many differences between Docker and virtual machines. Containers implement virtualization at the operating system level and directly reuse the local machine.

Operating system, while traditional virtual machines are implemented at the hardware level as shown in the figure below:

Insert image description here

Why use Docker

As a virtualization technology, docker has many advantages compared with traditional virtual machines:

Faster delivery and deployment

During the entire project process, docker can play its own advantages. When developing code, a development container can be constructed. After the development is completed, operation and maintenance personnel can directly use the developed container to deploy the project. Docker can quickly create and copy Containers, docker containers are very light and fast, and you can easily use containers to deploy test environments during later testing. It can quickly improve the efficiency of the entire chain.

Efficient capacity expansion

Because docker can run on any platform, including physical machines, virtual machines, various cloud environments, servers, etc., if you want to migrate a project to another platform, it is very simple and convenient. Docker’s compatibility and lightweight features, It allows you to easily implement operations such as server expansion and migration.

Higher resource utilization

Because of the lightweight characteristics of docker, thousands of docker containers can be run on a single host. The containers only consume system resources when running the project. The performance of the application is very high, but the system overhead is very small, which can ensure a high resource utilization.

Docker structure

Docker engine

The main components of the Docker engine are as follows:

picture

Server is a resident process that manages the entire docker interaction.

Implement communication between client and server.

Mirror image

An image is a read-only template of an environment. An image contains a virtual operating system environment and can install various project software you need, such as tomcat, mysql, etc. With the image, you can create a docker container based on the image. No matter where you are, you can use this image to copy the same container environment.

storehouse:

A warehouse is a place where images are placed centrally. It is mainly divided into public warehouses and private warehouses. The largest public warehouse is docker hub, which stores a large number of mature images for users to download and use. In China, there are Shisu Cloud, NetEase Cloud, etc. Of course, you can also create your own private warehouse on the local network.

container:

Docker uses containers to run applications. A container is a running instance of an image. We can create a container through a mature image and then run our own applications on it. If you are inside the company, you can install your own software for the required environment, and then generate the entire docker image. At this time, you can share the image with others, and everyone can execute the image, run the container, and have your previous That environment is very convenient to use.

Basic use of Docker

Common commands of Docker (take mysql as an example)

1: Get the image

You can use the docker pull command, such as docker pull mysql:8.0

2: List all images

docker images

You can see the downloaded image in your docker

$ docker imagesREPOSITORY               TAG                 IMAGE ID            CREATED             SIZEmysql:8.0          mysql:8.0    6a77ab6655b9        8 weeks ago       194.6 MB

3: Execute image

docker run --name mysql8.0 -p 3307:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0

4: View the running image

docker ps -a

5: Enter the mirror

Enter the mirror and run mysql

Command: docker exec -it mysql8.0 /bin/bash

Note: exec docker enters the container command -it. The service alias /bin/bash in the container indicates command line mode and -d background daemon mode startup to form two running modes.

Command: cd /usr/bin

Instruction: mysql -u root -p

Note: Enter the user directory in the container to start mysql and enter the password to connect successfully.

Successful installation

Otherwise, mysql can be operated normally.

6: Create an image

You can use Dockerfile to create images

docker build

Using docker commit to extend an image is relatively simple, but it is inconvenient to share it among a team. We can use docker build to create a new image. To do this, you first need to create a Dockerfile, which contains some instructions on how to create an image. You can refer to the Internet for this content.

After writing the Dockerfile, you can use docker build to generate the image.

This article mainly introduces docker technology

Finally, I would like to thank everyone who reads my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, if you can use it, you can take it directly:

Insert image description here

This information should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can also help you!  

Guess you like

Origin blog.csdn.net/nhb687095/article/details/132874939