1.准备一台最小安装的CentOS主机,保证此CentOS主机可以顺利访问Internet

  1. [root@hwj ~]# ip add
  2. 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  3. link/ether 00:0c:29:a0:b2:ad brd ff:ff:ff:ff:ff:ff
  4. inet 192.168.20.12/24 brd 192.168.20.255 scope global ens33
  5. valid_lft forever preferred_lft forever
  6. inet6 fe80::5cad:b1c4:fcb2:74b0/64 scope link
  7. valid_lft forever preferred_lft forever
  8. [root@hwj ~]# ping -c 2 www.baidu.com
  9. PING www.wshifen.com (103.235.46.39) 56(84) bytes of data.
  10. 64 bytes from 103.235.46.39 (103.235.46.39): icmp_seq=2 ttl=128 time=274 ms
  11. --- www.wshifen.com ping statistics ---
  12. 2 packets transmitted, 1 received, 50% packet loss, time 1009ms
  13. rtt min/avg/max/mdev = 274.934/274.934/274.934/0.000 ms

2.关闭防火墙、selinux和清空iptables

  1. [root@hwj ~]# systemctl stop firewalld
  2. [root@hwj ~]# systemctl disable firewalld
  3. Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
  4. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
  5. [root@hwj ~]# setenforce 0
  6. [root@hwj ~]# vi /etc/sysconfig/selinux
  7. SELINUX=disabled
  8. [root@hwj ~]# getenforce
  9. Permissive
  10. [root@hwj ~]# iptables -X
  11. [root@hwj ~]# iptables -F
  12. [root@hwj ~]# iptables -Z
  13. [root@hwj ~]# iptables-save
  14. # Generated by iptables-save v1.4.21 on Thu Feb 24 12:55:01 2022
  15. *filter
  16. :INPUT ACCEPT [48:2820]
  17. :FORWARD ACCEPT [0:0]
  18. :OUTPUT ACCEPT [29:2204]
  19. COMMIT
  20. # Completed on Thu Feb 24 12:55:01 2022

3.修改yum源为阿里云

  1. [root@hwj ~]# yum install -y wget
  2. [root@hwj ~]# cd /etc/yum.repos.d
  3. [root@hwj yum.repos.d]# mkdir backup
  4. [root@hwj yum.repos.d]# mv CentOS-*.repo backup
  5. [root@hwj yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  6. --2022-02-24 13:00:28-- https://mirrors.aliyun.com/repo/Centos-7.repo
  7. 正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 182.105.147.116, 182.105.147.118, 182.105.147.115, ...
  8. 正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|182.105.147.116|:443... 已连接。
  9. 已发出 HTTP 请求,正在等待回应... 200 OK
  10. 长度:2523 (2.5K) [application/octet-stream]
  11. 正在保存至: “/etc/yum.repos.d/CentOS-Base.repo
  12. 100%[==============================================================================>] 2,523 --.-K/s 用时 0.007s
  13. 2022-02-24 13:00:28 (331 KB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo [2523/2523])
  14. [root@hwj yum.repos.d]# yum clean all && yum makecache && yum repolist
  15. 已加载插件:fastestmirror
  16. 源标识 状态 源名称
  17. base/7/x86_64 10,072 CentOS-7 - Base - mirrors.aliyun.com
  18. extras/7/x86_64 500 CentOS-7 - Extras - mirrors.aliyun.com
  19. updates/7/x86_64 3414 CentOS-7 - Updates - mirrors.aliyun.com

4.设置时间同步

  1. [root@hwj ~]# yum install -y ntp net-tools
  2. [root@hwj ~]# ntpdate cn.pool.ntp.org
  3. 24 Feb 13:11:05 ntpdate[9237]: adjust time server 139.199.214.202 offset -0.007169 sec

5.安装Docker依赖环境(运行必备主件)

  1. [root@hwj ~]# yum install -y yum-utils device-mapper-persisitent-data lvm2

6.配置阿里云Docker-CE源

  1. [root@hwj ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  2. 已加载插件:fastestmirror
  3. adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  4. grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
  5. repo saved to /etc/yum.repos.d/docker-ce.repo

7.安装Docker-CE最新版本并查看是否正常安装

  1. [root@hwj ~]# yum install docker-ce -y
  2. [root@hwj ~]# docker -v
  3. Docker version 20.10.12, build e91ed57
  4. [root@hwj ~]# docker version
  5. Client: Docker Engine - Community
  6. Version: 20.10.12
  7. API version: 1.41
  8. Go version: go1.16.12
  9. Git commit: e91ed57
  10. Built: Mon Dec 13 11:45:41 2021
  11. OS/Arch: linux/amd64
  12. Context: default
  13. Experimental: true

8.登录阿里云、添加docker本地镜像加速器

image.png

  1. [root@hwj ~]# mkdir -p /etc/docker
  2. [root@hwj ~]# tee /etc/docker/daemon.json <<-'EOF'
  3. {
  4. "registry-mirrors": ["https://dgodf4l3.mirror.aliyuncs.com"]
  5. }
  6. EOF
  7. [root@hwj ~]# systemctl daemon-reload
  8. [root@hwj ~]# systemctl restart docker

9.启动Docker服务,并检查信息

  1. [root@hwj ~]# systemctl start docker
  2. [root@hwj ~]# systemctl enable docker
  3. Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
  4. [root@hwj ~]# docker info
  5. Client:
  6. Context: default
  7. Debug Mode: false
  8. Plugins:
  9. app: Docker App (Docker Inc., v0.9.1-beta3)
  10. buildx: Docker Buildx (Docker Inc., v0.7.1-docker)
  11. scan: Docker Scan (Docker Inc., v0.12.0)
  12. Server:
  13. Containers: 0
  14. Running: 0
  15. Paused: 0
  16. Stopped: 0
  17. Images: 0
  18. Server Version: 20.10.12
  19. Storage Driver: overlay2
  20. Backing Filesystem: extfs
  21. Supports d_type: true
  22. Native Overlay Diff: true
  23. userxattr: false
  24. Logging Driver: json-file
  25. Cgroup Driver: cgroupfs
  26. Cgroup Version: 1
  27. Plugins:
  28. Volume: local
  29. Network: bridge host ipvlan macvlan null overlay
  30. Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
  31. Swarm: inactive
  32. Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
  33. Default Runtime: runc
  34. Init Binary: docker-init
  35. containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
  36. runc version: v1.0.2-0-g52b36a2
  37. init version: de40ad0
  38. Security Options:
  39. seccomp
  40. Profile: default
  41. Kernel Version: 3.10.0-693.el7.x86_64
  42. Operating System: CentOS Linux 7 (Core)
  43. OSType: linux
  44. Architecture: x86_64
  45. CPUs: 2
  46. Total Memory: 3.686GiB
  47. Name: hwj
  48. ID: OTQT:YQJF:XWCC:7SHS:AE43:ZETC:3K76:SA45:HBS2:5WK2:B45D:SGIB
  49. Docker Root Dir: /var/lib/docker
  50. Debug Mode: false
  51. Registry: https://index.docker.io/v1/
  52. Labels:
  53. Experimental: false
  54. Insecure Registries:
  55. 127.0.0.0/8
  56. Registry Mirrors:
  57. https://dgodf4l3.mirror.aliyuncs.com/
  58. Live Restore Enabled: false

10.运行镜像

  1. [root@hwj ~]# docker run -itd -p 80:80 nginx
  2. Unable to find image 'nginx:latest' locally
  3. latest: Pulling from library/nginx
  4. latest: Pulling from library/nginx
  5. 5eb5b503b376: Pull complete
  6. 1ae07ab881bd: Pull complete
  7. 78091884b7be: Pull complete
  8. 091c283c6a66: Pull complete
  9. 55de5851019b: Pull complete
  10. b559bad762be: Pull complete
  11. Digest: sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767
  12. Status: Downloaded newer image for nginx:latest
  13. a8c683bbb53183e27971b72d28c270d2c4d9917fa350d9bde9c2b5d20e53fefc

/image.png