Introduction to docker and a complete collection of common commands (super detailed)


Introduction to Docker

1. What is Docker

Docker is an open source application container engine, which is developed based on the go language and complies with the Apache2.0 open source protocol. Using Docker allows developers to package their applications and dependencies into a portable container, and then publish it to any Linux machine, and it can also achieve virtualization. Docker containers completely use the sandbox mechanism, and there will be no interfaces between them, which ensures the security between the containers.

Docker was born in early 2013 and currently has two versions, Community Edition (CE, Community Edition) and Enterprise Edition (EE, Enterprise Edition). Among them, the Docker Community Edition is free and open source, which is an ideal choice for individuals and small teams; the Docker Enterprise Edition is charged, which is specially provided for enterprises and large IT teams, and is used in more demanding commercial applications. .

For starters, using the Docker Community Edition will suffice.

2. The characteristics of Docker

When learning a technology, only by understanding the characteristics of the technology can it be better used in practice. As a current mainstream open source container engine, Docker has the following main features.

1. Faster Delivery and Deployment

Developers can use a standard Docker image to build a set of development containers. After the development is completed, operation and maintenance personnel can directly use this container to deploy code. Docker can quickly create containers and iterate applications quickly, and make the entire process visible, making it easier for other members of the team to understand how applications are created and work. The Docker container is light and starts quickly, which can save a lot of development, testing and deployment time.

2. more efficient virtualization

When the Docker container is running, it does not need the support of additional virtual machine programs. Because it is kernel-level virtualization, it can achieve higher performance and efficiency.

3. Easier Migration and Scaling

Docker containers can run on almost any platform, including physical machines, virtual machines, public clouds, private clouds, personal computers, and servers. This good compatibility allows users to directly migrate an application from one platform to another, which is very conducive to application migration and expansion.

4. easier management

With Docker, only a small modification is required to replace a large number of update work in the past. All changes are distributed and updated incrementally for automated and efficient management.

In addition to the above characteristics, Docker also has the characteristics of logical separation of responsibilities, suitable for use with service-oriented architecture, etc., which will not be described in detail here, and readers can experience it in depth during the learning process.

3. The difference between Docker and virtual machine

After understanding the concept and characteristics of Docker, I believe many people will have doubts about the difference between Docker and virtual machines, so what is the difference between them? The following is a comparison chart to illustrate the main differences between the two, as shown in Figure 1.

insert image description here

Figure 1 Comparison between Docker and virtual machines

It can be seen from the comparison in Figure 1 that the virtual machine runs on the client operating system at each application level, which is resource-intensive. Since the generated disk image and the operating system settings of the application intersect with each other, the virtual machine has a strong dependence on the system. Once a problem occurs in the system, the files and security patches that the virtual machine depends on may be lost.

Containers in Docker are process-based isolation , multiple containers can share a single kernel, and the configuration required to create a Docker container image does not depend on the host system. It is precisely because of the isolation of the direct configuration of the container that there is no cross-configuration between the containers, so Docker applications can run anywhere.


Docker commands

The image in docker is like the Class in our java, and the container is based on this image. The instances constructed are similar to the instance objects constructed based on the Class in our java. Please forgive me for misunderstanding...

in short as i understand

docker 镜像: ----java中 class

docker容器 : ----java中 class new 出来的实例对象

This article is not only a complete collection of blunt commands, but also a step-by-step summary of my personal learning and use of docker. Through examples one by one, I can deepen my understanding and memory of docker-related commands.

1.docker basic commands

start docker

systemctl start docker

close docker

systemctl stop docker

restart docker

systemctl restart docker

The docker setting starts automatically when the service starts

systemctl enable docker

View docker running status

------If you enter the command during operation, you will see green active

systemctl status docker

insert image description here

View docker version number information

docker version
docker info

insert image description here
insert image description here

docker help command

If you forget some commands, you can use this to view and review

docker --help
docker pull --help

insert image description here

2.docker image command

docker search image id or name: search for images of keywords in the Docker Hub (or other image warehouses such as Ali image) warehouse
docker pull image id or name: download the image from the warehouse, if you want to specify the version, you must specify it after the colon
docker images: list downloaded images, view images
docker rmi image id or name: delete local image
docker rmi -f image id or name: delete image
docker build: build image

View the list of docker images in your server

docker images

search mirror

docker search 镜像名
docker search --filter=STARS=9000 mysql 搜索 STARS >9000的 mysql 镜像

Pull image without adding tag (version number) to pull the latest version latest of the image in the docker warehouse, and adding :tag to pull the specified version

docker pull 镜像名 
docker pull 镜像名:tag

Pull the latest version of mysql (the latest version is pulled by default if the version number is not specified)

docker pull mysql

insert image description here

Let's pull a specified version number image again. As for the version number, you can check it in docker hub

Docker official image search
insert image description here
insert image description here
For example: pull mysql 5.7.40

docker pull mysql:5.7.40

insert image description here

Run the image ----for example, pull a tomcat and run it to try

docker pull tomcat

As shown in the figure below: the latest version of tomcat is pulled
insert image description here

docker run 镜像名
docker run 镜像名:Tag

3.docker container command

docker ps: list running containers
docker ps -a: view all containers, including not running
docker stop container id or name: stop the container
docker kill container id: force stop the container
docker start container id or name: start the stopped container
docker inspect container id: view all the information of
the container docker container logs container id: view the container log
docker top container id: view the process in the container
docker exec -it container id /bin/bash: enter the container
exit: exit the container
docker rm container id or name: remove stopped container
docker rm -f container id: remove running container
docker exec -it container id sh: enter container

Guess you like

Origin blog.csdn.net/qq_25919879/article/details/127054566