Docker安装

Docker安装 · 语雀 (yuque.com)   不习惯可以进语雀看

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

[root@hwj ~]# ip add
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a0:b2:ad brd ff:ff:ff:ff:ff:ff
    inet 192.168.20.12/24 brd 192.168.20.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::5cad:b1c4:fcb2:74b0/64 scope link 
       valid_lft forever preferred_lft forever
[root@hwj ~]# ping -c 2 www.baidu.com
PING 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 1009ms
rtt 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 firewalld
Removed 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/selinux 
SELINUX=disabled
[root@hwj ~]# getenforce
Permissive
[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.007s  
2022-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.com
extras/7/x86_64          500                     CentOS-7 - Extras - mirrors.aliyun.com 
updates/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.org
24 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
已加载插件:fastestmirror
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

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

[root@hwj ~]#  yum install docker-ce -y
[root@hwj ~]# docker -v
Docker version 20.10.12, build e91ed57
[root@hwj ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.12
 API version:       1.41
 Go version:        go1.16.12
 Git commit:        e91ed57
 Built:             Mon Dec 13 11:45:41 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      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 docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@hwj ~]# docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  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: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.12
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-693.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.686GiB
 Name: hwj
 ID: OTQT:YQJF:XWCC:7SHS:AE43:ZETC:3K76:SA45:HBS2:5WK2:B45D:SGIB
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://dgodf4l3.mirror.aliyuncs.com/
 Live Restore Enabled: false

10.运行镜像

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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我不是生花

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值