About Docker
Docker is an open source container engine that helps deliver applications faster. Docker isolates the application and infrastructure layers and manages the infrastructure as a program. Use Docker to package, test, and deploy applications faster, and shorten the cycle from writing to deploying and running code.
1. Docker requires the kernel version of the CentOS system to be higher than 3.10
uname -r
2. Log in to Centos with root privileges to ensure that the yum package is updated to the latest
sudo yum -y update
3. Uninstall the old version (if you have installed the old version)
sudo yum remove -y docker*
4. Install the required software package, yum-util provides yum-config-manager function
sudo yum install -y yum-utils
5. Set the yum source and update the package index of yum
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache fast
6. You can view all docker versions in all warehouses, and select a specific version to install
sudo yum list docker-ce --showduplicates | sort -r
7. Install docker
sudo yum install -y docker-ce-3:20.10.6-3.el7.x86_64
8. Start and join the startup
sudo systemctl start docker && systemctl enable docker
9. Verify that the installation is successful (there are two parts, client and service, indicating that the docker installation and startup are successful)
docker version
10. In addition, it is generally necessary to configure the docker image accelerator (such as Alibaba Cloud's)
cd /etc/docker
Check if there is daemon.json, which is the default configuration file of docker. If not, modify it.
vim daemon.json
{
"registry-mirrors": ["https://78ltb1le.mirror.aliyuncs.com"]
}
wq save and exit, then restart the docker service
sudo systemctl daemon-reload
sudo systemctl restart docker
11. When restarting the docker service, an error was reported suddenly
Then start troubleshooting:
- Through the "systemctl status docker.service" command prompted by the system, can Kangkang see what is tricky?
- It seems that we can't see where the specific problem is, so let's check the Linux system operation log to see if we can find anything (the last 200 lines can be checked):
tail -200f /var/log/messages
- According to the operation log of the Linux system, it is found that the copied content of the daemon.json file of docker just now has wrong characters, so I went to Alibaba Cloud to re-copy a daemon.json file that covered the original problem, and executed "sudo" again systemctl daemon-reload" and "sudo systemctl restart docker" commands, the problem is solved!
12. Uninstall docker
# 依次执行下面四条命令即可
1. yum remove -y docker*
2. rm -rf /etc/systemd/system/docker.service.d
3. rm -rf /var/lib/docker
4. rm -rf /var/run/docker