Docker is an open source containerization platform that uses containerization technology to build, deploy, and run applications in a more efficient and convenient way. Compared with traditional virtualization methods, Docker has many advantages and advantages. In the serial port server self-built MQTT server implementation communication tutorial based on the EMQX platform we published earlier, we briefly introduced the tutorial on installing Docker and deploying the EMQX service in Docker. Next, we will introduce the advantages of Docker and the key points to pay attention to during use. .

Advantages of Docker
Lightweight and efficient: Docker uses container virtualization technology to package applications and all their dependencies in independent containers. Containers start up faster and use fewer resources than traditional virtual machines, allowing applications to run in a more efficient manner.

Portable and flexible: Docker containerized applications can run in any environment that supports Docker, without being restricted by the underlying operating system or hardware. This portability facilitates developers to deploy applications to different environments and avoid compatibility issues caused by environmental differences.

Rapid deployment: With the help of the Docker image mechanism, developers can package applications and their dependencies into images, and only need to run the image when deploying, which greatly simplifies the deployment process and saves time and energy.

Flexible expansion: Docker allows users to scale horizontally by creating multiple container instances to meet different load and traffic needs. At the same time, Docker supports interconnection and communication between containers, allowing applications to be organized in a microservice manner, improving the flexibility and scalability of the system.

This tutorial will comprehensively explain the process of Docker from server installation to deployment. The steps are as follows:

1. Terminal connection command:
An SSH connection can be established with the server through the following terminal connection command:

ssh root@[ip address] -p [port number]

2. System update:
To ensure that the system is up to date, execute the following command to update the system:

apt update -y && apt upgrade -y

3. Delete the SSH host key:
If you encounter a change in the SSH host key, please use the following command to delete the original key:

nano ~/.ssh/known_hosts

4. DD a pure system:
For ordinary users, there is no need for system installation, because the server has already done basic protection work for novice users, such as prohibiting password login and root user login. However, if you insist on system installation, you can follow these steps:

sudo -i #switch to root user

sudo apt update -y #Update software package

Docker installation notes:
This installation tutorial does not apply to OpenVZ/LXC architecture systems. Please refer to the following sources for details:

5. DD script installation (default is Debian10, you need to modify the root password and SSH port according to your needs):
Run the following command, replacing "custom root password" and "custom ssh port" with what you need:

bash <(wget --no-check-certificate -qO- '') -d 10 -v 64 -p "Customized roo password" -port "custom ssh port", wait for about 15 to 30 minutes, you can try to establish a connection with the server, or use the ping command to check domain name connectivity.

6. View system information:
To view system details, execute the following command: hostnamectl # or uname -r

Install necessary tools:
1. Install necessary tools such as sudo, wget, curl and nano, and execute the following commands:

sudo apt update #Update package list

apt install sudo wget curl nano

2. Add official backports source for Debian 10 (update software library):
Edit the /etc/apt/sources.list file and add the following at the end (using the nano editor: press ctrl+o to save and exit, press ctrl+x to exit without saving):

deb buster-backports main

3. Refresh the software library and query the latest official Debian kernel version and install it. Please ensure that the kernel version is installed correctly based on the server type ("amd64" in this example):

sudo apt update && sudo apt -t buster-backports install linux-image-amd64

4. Modify the kernel parameter configuration file sysctl.conf:

Edit the /etc/sysctl.conf file and add the following content:



Restart the server for kernel updates and configuration to take effect: sudo reboot

Update the GRUB boot menu to prevent it from not updating when installing a new kernel. Execute the following command to update the GRUB boot menu: sudo update-grub

Then restart the system to make the new kernel take effect: sudo reboot

After rebooting, you can run the hostnamectl or uname -r command again to confirm whether the kernel version has been updated.

To verify that the fq algorithm is enabled correctly, run the following command: lsmod | grep fq

If enabled correctly, the following output will be returned: root@iZt4nfn72irn8xvvdxjiluZ:~# lsmod | grep fq

sch_fq 20480 2

Change the time:

First, the server time needs to be adjusted to local time. If the server is located in Hong Kong and the time is consistent with the local time, you can ignore this step. If you are located in Europe and the United States, you can perform the following steps to adjust the time:

sudo -i #switch to root user

apt update -y && apt upgrade -y #Update software package

View time: timedatectl

After DD is completed, you may find that the time has changed to New York time and needs to be adjusted: timedatectl list-timezones #List all time zones
Docker set time zone

Set the time zone to Asia/Shanghai: sudo timedatectl set-timezone Asia/Shanghai

Then run the following command again to check the time: timedatectl


Install commonly used software: apt install sudo curl wget
SWAP is a virtual memory mechanism in Linux used to store temporary data when physical memory is insufficient. Similar to virtual memory in Windows, but in Linux, you can use files or partitions as virtual memory. For servers with small memory, SWAP is important and can improve operating efficiency. Here are the steps to add SWAP via script:

wget -O && chmod +x && clear && ./
Docker virtual memory

Install Docker and Docker-compose:
Update and install necessary software:
apt-get update && apt-get install -y wget vim

Install Docker in mainland China:
Run the following command to install Docker:

wget -qO- | bash

Note: If the "sudo: unable to resolve host [hostname]" error occurs, please edit the /etc/hosts file, add a space after "localhost", and then add the corresponding [hostname] content.
Docker virtual memory

Check the Docker version:

To view the installed Docker version, execute the following command: docker -v

Set Docker to start automatically when booting:

Use the following command to enable Docker to start automatically at boot: systemctl enable docker

Uninstall Docker steps
To uninstall Docker, execute the following command:

sudo apt-get purge docker-ce docker-ce-cli

sudo rm -rf /var/lib/docker

sudo rm -rf /var/lib/containerd

Install Docker-compose in non-Mainland China regions:
Execute the following command to install Docker-compose:

curl -SL -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

Check the Docker-compose version:
To view the installed Docker-compose version, execute the following command: docker-compose --version

Docker is a lightweight and flexible containerization technology that brings numerous advantages to building, deploying, and running applications. With the help of Docker, developers and operations teams can not only simplify the application building and deployment process, but also improve application portability and performance. This is because Docker encapsulates the application's dependencies and configuration, allowing the application to run in any environment, whether it is a local development environment or a production environment.

There are many issues to pay attention to when using Docker. First of all, you need to pay attention to version compatibility to ensure that Docker's various components and plug-ins are compatible and work properly. Secondly, you need to pay attention to security, especially whether the source and content of the image are safe and trustworthy to avoid the risk of the system being attacked or contaminated. For this purpose, you can use trusted image warehouses such as Docker Hub and take security measures, such as restricting access and strengthening password policies. In addition, you also need to pay attention to resource management and performance monitoring when using Docker. On the one hand, the elasticity and flexibility of Docker can easily cause too many Docker containers and waste resources. Therefore, reasonable resource management and allocation of Docker containers is required, such as using tools such as Docker Compose to manage containers. On the other hand, the high performance of Docker also puts forward higher requirements for system monitoring and debugging, which requires the use of appropriate monitoring tools and technologies, such as Prometheus and Grafana.

To sum up, Docker, as an advanced containerization technology, brings many advantages and conveniences to developers and operation and maintenance teams, but it also requires attention to version compatibility, security, image source credibility, and resource management. and performance monitoring to ensure system stability and security. Only in this way can the advantages of Docker be truly utilized to make applications more efficient and secure throughout their life cycles.

At this point, this tutorial is over and you can start deploying and installing it. I believe that through this study, everyone can master the installation of Docker.