[Detailed explanation and problem solving of Docker installation steps for Linux deployment]

1. Docker installation

1. Install dependent environment, yum-utils

	yum -y install yum-utils device-mapper-persistent-data lvm2

Insert image description here
Note:
Use the yum tool to download
yum, which is a software package management tool. You can view the help information of yum
by executing man yum.

2. Set the mirror source and add the docker warehouse location for the yum source.

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Insert image description here

3. Install Docker

①: Execute the command to improve the speed of software installation (caching the software package information locally in advance to improve the speed of searching and installing software)

yum makecache fast

Insert image description here

②: Install docker (docker-ce community version and ee is the enterprise version)

yum install docker-ce docker-ce-cli containerd.io

Insert image description here
Insert image description here

③: Specify the docker image storage directory

vim /etc/docker/daemon.json
进行编辑(json格式)
 {
    
    "graph": "/data/docker-data"}

Insert image description here

④: Start and set it to start automatically at boot (because you added the log generation path, something may go wrong, don’t panic!! You can check the solution later)

1): Refresh the daemon.json file

systemctl daemon-reload

2): Start the Docker service

systemctl start docker
sudo systemctl start docker
-- 重启
systemctl restart docker

3): Set the boot to start automatically

systemctl enable docker

4): test

docker run hello-world

5:): View the current status of docker

systemctl status docker
查看具体的错误信息
systemctl status docker -l
systemctl status docker.service
# 查看docker的版本信息
docker version
# 查看docker是否启动
ps -ef | grep docker
# 设置docker开机自启动
systemctl enable docker

Second, the installation process problems:

1. The docker.service cannot be found in the linux system

Insert image description here
Excuting an order:

locate docker.service

2. The locate command cannot be found ====

Insert image description here
Solution:
①: Install the "locate" command. Run the "yum install mlocate" command while connected to the Internet. as follows:

[root@localhost b]# yum install mlocate

②. After the installation is complete, search for docker.service and an error will be reported.

[root@localhost b]# locate  docker.service
locate: 无法执行 stat () `/var/lib/mlocate/mlocate.db': 没有那个文件或目录

③. Search again after executing updatedb

[root@localhost b]# updatedb
[root@localhost b]# locate docker.service
/etc/inittab

3. But an error will still be reported (the docker service fails to start)

Failed to start Docker Application Container Engine.
Stopped Docker Application Container Engine.
docker. service failed.
scheduling restart.

Insert image description here
It may be that the file format is wrong when specifying the docker image storage directory
. Solution:
①. Modify the daemon.json file format
②. Delete the file without specifying the image path.

4. Solve the docker startup error: Job for docker.service failed because the control process exited with error code

①: Execute:

sudo systemctl start docker
## 查看服务信息:
systemctl status docker.service

Error:
Insert image description here
Solved:

1、进入docker目录:cd /etc/docker/
2、修改daemon的类型:mv daemon.json daemon.conf
3、重启docker:systemctl restart docker

Result:
Insert image description here
Execute the settings to automatically restart
systemctl enable docker and report an error.
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

Reference link
https:/ /www.cnblogs.com/OnlyDreams/p/8432109.html

Three, docker commonly used

## 是否安装docker
docker version
## 重启docker
service docker restart
## 停止docker
service docker stop
## 检查修改结果
docker info
## 卸载docker
sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine
## 查看本地镜像
docker images
## 查看当前运行的容器信息
docker ps
## 启动具体容器
docker start + id
## 进入容器
docker exec -it +容器ID /bin/bash
## 全部停止
docker stop $(docker ps -a -q)
## 进入java容器
docker exec -it java bash

## Docker帮助docker
docker --help  
## 查看Docker版本
docker --version
## 搜索镜像文件
docker search <image> 
## 拉取镜像文件,
docker search mysql docker pull <image> 
## 查看已经拉取下来的所以镜像文件
docker pull mysql docker images  #删除指定镜像文件#发布指定镜像文件
docker rmi <image>
## 查看正在运行的所有镜像
docker run --name <name> -p 80:8080 -d <image> 
docker ps
## 查看所有发布的镜像
docker ps -a
## 删除执行已发布的镜像
docker rm <image>

Some reference articles:
Detailed steps to install Docker summarize
how Docker installs basic image services

Guess you like

Origin blog.csdn.net/m0_49762804/article/details/131398587
Recommended