1.准备一台最小安装的CentOS主机,保证此CentOS主机可以顺利访问Internet
[root@hwj ~]# ip add2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:a0:b2:ad brd ff:ff:ff:ff:ff:ffinet 192.168.20.12/24 brd 192.168.20.255 scope global ens33valid_lft forever preferred_lft foreverinet6 fe80::5cad:b1c4:fcb2:74b0/64 scope linkvalid_lft forever preferred_lft forever[root@hwj ~]# ping -c 2 www.baidu.comPING www.wshifen.com (103.235.46.39) 56(84) bytes of data.64 bytes from 103.235.46.39 (103.235.46.39): icmp_seq=2 ttl=128 time=274 ms--- www.wshifen.com ping statistics ---2 packets transmitted, 1 received, 50% packet loss, time 1009msrtt min/avg/max/mdev = 274.934/274.934/274.934/0.000 ms
2.关闭防火墙、selinux和清空iptables
[root@hwj ~]# systemctl stop firewalld[root@hwj ~]# systemctl disable firewalldRemoved symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.[root@hwj ~]# setenforce 0[root@hwj ~]# vi /etc/sysconfig/selinuxSELINUX=disabled[root@hwj ~]# getenforcePermissive[root@hwj ~]# iptables -X[root@hwj ~]# iptables -F[root@hwj ~]# iptables -Z[root@hwj ~]# iptables-save# Generated by iptables-save v1.4.21 on Thu Feb 24 12:55:01 2022*filter:INPUT ACCEPT [48:2820]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [29:2204]COMMIT# Completed on Thu Feb 24 12:55:01 2022
3.修改yum源为阿里云
[root@hwj ~]# yum install -y wget[root@hwj ~]# cd /etc/yum.repos.d[root@hwj yum.repos.d]# mkdir backup[root@hwj yum.repos.d]# mv CentOS-*.repo backup[root@hwj yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo--2022-02-24 13:00:28-- https://mirrors.aliyun.com/repo/Centos-7.repo正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 182.105.147.116, 182.105.147.118, 182.105.147.115, ...正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|182.105.147.116|:443... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度:2523 (2.5K) [application/octet-stream]正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”100%[==============================================================================>] 2,523 --.-K/s 用时 0.007s2022-02-24 13:00:28 (331 KB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])[root@hwj yum.repos.d]# yum clean all && yum makecache && yum repolist已加载插件:fastestmirror源标识 状态 源名称base/7/x86_64 10,072 CentOS-7 - Base - mirrors.aliyun.comextras/7/x86_64 500 CentOS-7 - Extras - mirrors.aliyun.comupdates/7/x86_64 3414 CentOS-7 - Updates - mirrors.aliyun.com
4.设置时间同步
[root@hwj ~]# yum install -y ntp net-tools[root@hwj ~]# ntpdate cn.pool.ntp.org24 Feb 13:11:05 ntpdate[9237]: adjust time server 139.199.214.202 offset -0.007169 sec
5.安装Docker依赖环境(运行必备主件)
[root@hwj ~]# yum install -y yum-utils device-mapper-persisitent-data lvm2
6.配置阿里云Docker-CE源
[root@hwj ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo已加载插件:fastestmirroradding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repograbbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.reporepo saved to /etc/yum.repos.d/docker-ce.repo
7.安装Docker-CE最新版本并查看是否正常安装
[root@hwj ~]# yum install docker-ce -y[root@hwj ~]# docker -vDocker version 20.10.12, build e91ed57[root@hwj ~]# docker versionClient: Docker Engine - CommunityVersion: 20.10.12API version: 1.41Go version: go1.16.12Git commit: e91ed57Built: Mon Dec 13 11:45:41 2021OS/Arch: linux/amd64Context: defaultExperimental: true
8.登录阿里云、添加docker本地镜像加速器

[root@hwj ~]# mkdir -p /etc/docker[root@hwj ~]# tee /etc/docker/daemon.json <<-'EOF'{"registry-mirrors": ["https://dgodf4l3.mirror.aliyuncs.com"]}EOF[root@hwj ~]# systemctl daemon-reload[root@hwj ~]# systemctl restart docker
9.启动Docker服务,并检查信息
[root@hwj ~]# systemctl start docker[root@hwj ~]# systemctl enable dockerCreated symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.[root@hwj ~]# docker infoClient:Context: defaultDebug Mode: falsePlugins:app: Docker App (Docker Inc., v0.9.1-beta3)buildx: Docker Buildx (Docker Inc., v0.7.1-docker)scan: Docker Scan (Docker Inc., v0.12.0)Server:Containers: 0Running: 0Paused: 0Stopped: 0Images: 0Server Version: 20.10.12Storage Driver: overlay2Backing Filesystem: extfsSupports d_type: trueNative Overlay Diff: trueuserxattr: falseLogging Driver: json-fileCgroup Driver: cgroupfsCgroup Version: 1Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5drunc version: v1.0.2-0-g52b36a2init version: de40ad0Security Options:seccompProfile: defaultKernel Version: 3.10.0-693.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 2Total Memory: 3.686GiBName: hwjID: OTQT:YQJF:XWCC:7SHS:AE43:ZETC:3K76:SA45:HBS2:5WK2:B45D:SGIBDocker Root Dir: /var/lib/dockerDebug Mode: falseRegistry: https://index.docker.io/v1/Labels:Experimental: falseInsecure Registries:127.0.0.0/8Registry Mirrors:https://dgodf4l3.mirror.aliyuncs.com/Live Restore Enabled: false
10.运行镜像
[root@hwj ~]# docker run -itd -p 80:80 nginxUnable to find image 'nginx:latest' locallylatest: Pulling from library/nginxlatest: Pulling from library/nginx5eb5b503b376: Pull complete1ae07ab881bd: Pull complete78091884b7be: Pull complete091c283c6a66: Pull complete55de5851019b: Pull completeb559bad762be: Pull completeDigest: sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767Status: Downloaded newer image for nginx:latesta8c683bbb53183e27971b72d28c270d2c4d9917fa350d9bde9c2b5d20e53fefc
/
