Practical case - Docker engine installation

Docker engine installation

1. Basic preparation

Single node, IP address is customized, host name ismaster, node system is[CentOS7.5_1804]

2. Implementation steps

2.1. Basic environment configuration

(1) Configure yum source

Upload the provided compressed packageDocker.tar.gz to the /root directory and decompress it

# 上传步骤省略,自行通过Xftp等软件上传
[root@master ~]# tar -zxvf Docker.tar.gz

Configure the local yum source (self-cleaning the system’s own source)

[root@master ~]# vi /etc/yum.repos.d/local.repo
[kubernetes]
name=kubernetes
baseurl=file:///root/Docker
gpgcheck=0
enable=1
(2) Firewall rule configuration (clear all firewall rules)
[root@master ~]# iptables -F
[root@master ~]# iptables -X
[root@master ~]# iptables -Z
[root@master ~]# iptables-save
(3) Configure SElinux
[root@master ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
#也可以直接使用vi编辑器修改上述内容
[root@master ~]# reboot
(4) Close the swap partition
[root@master ~]# swapoff -a
[root@master ~]# sed -i 's/\/dev\/mapper\/centos-swap/\#\/dev\/mapper\/centos-swap/g' /etc/fstab
#查看交换分区
[root@master ~]# free -h
(5) Turn on routing forwarding

Use the vi editor to append the following statement under the /etc/sysctl.conf file, or use the following command to append the following statement after the /etc/sysctl.conf file, and finally pass sysctl -p takes effect in the configuration file.

[root@master ~]# cat >> /etc/sysctl.conf << EOF
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
或者:
[root@master ~]#vi /etc/sysctl.conf
#补充以下内容
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1

#生效配置文件
[root@master ~]# modprobe br_netfilter
[root@master ~]# sysctl -p

2.2. Docker engine installation (modify the network card to connect to the external network)

(1) Add Yum source

Use commands to add Alibaba Cloud CentOS7 Yum source files and Docker Yum sources; or use wget and other commands to download the above repo files yourself and put them under /etc/yum.repol.d/.

#CentOS源
curl -o /etc/yum.repos.d/Centos-7.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#Docker源
curl -o /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
#配置完成后检查源:
yum clean all && yum repolist

yum source information

(2) Install dependency packages
yum install -y yum-utils device-mapper-persistent-data
(3) Install Docker-ce

Install the specified Docker version here

# 查看Docker相关软件包
yum list docker-ce --showduplicates | sort -r
# 安装指定版本
yum install docker-ce-18.09.6 docker-ce-cli-18.09.6 containerd.io -y
(4) Start Docker
# 重新加载服务的配置文件
systemctl daemon-reload
# 重启Docker服务
systemctl restart docker
# 设置Docker开机自启
systemctl enable docker
# 输出docker信息
docker info
(5) Test Docker

Download the image containing Nginx web server from, start it with this Image, the physical machine and Set the port mapping of the container and test the welcome page. First set up Docker domestic image acceleration and add the following content in : 公共的RegistryImage容器
/etc/docker/daemon.json

[root@master ~]# vi /etc/docker/daemon.json
# 添加加速地址
{
    
    
        "registry-mirrors":["https://registry.docker-cn.com"]
}
# 重启Docker
systemctl restart docker
#查找镜像
docker search nginx
#拉取nginx镜像
docker pull nginx
#查看镜像
docker images
#运行容器并配置端口映射
docker run -itd -p 80:80 nginx:latest
#查看容器
docker ps -a

The physical machine can be verified by accessing the browserhttp://(虚拟机ip)/. As shown in the following figure, it is successful.
nginx service successfully started page

Guess you like

Origin blog.csdn.net/qq_44927958/article/details/134158668