1. 程式人生 > 其它 >快速部署docker環境(照做就行)

快速部署docker環境(照做就行)

Docker是一個容器技術。具有很強的可移植性。從本質上來說,他是一個虛擬機器。以映象為基礎單位,可以將單個專案分批的做好打成包。然後具有很強的可移植性。彼此之間不影響。下次要是誰需要,就可以直接拿出來用了。
下面我們來介紹一下,基於Centos 7 系統環境下,如何快速安裝docker環境!
[root@localhost ~]# ifconfig //檢視伺服器的ip地址,ens33是我的本地網絡卡地址
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.4 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::617f:ef93:80d4:e14e prefixlen 64 scopeid 0x20<link>
inet6 240e:3a2:745:8d30:ea90:dfb7:2133:6e48 prefixlen 64 scopeid 0x0<global>
ether 00:0c:29:87:af:a6 txqueuelen 1000 (Ethernet)
RX packets 352908 bytes 167723050 (159.9 MiB)
RX errors 0 dropped 235 overruns 0 frame 0
TX packets 108366 bytes 9290223 (8.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 1828 bytes 160628 (156.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1828 bytes 160628 (156.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:8e:d3:64 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


測試一下伺服器是否可以上網
[root@localhost ~]# ping www.baidu.com //ping 公網域名 。可以看見icmp資料包時就可以了。
PING www.a.shifen.com (180.101.49.11) 56(84) bytes of data.
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=1 ttl=54 time=5.57 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=2 ttl=54 time=5.94 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=3 ttl=54 time=4.62 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=4 ttl=54 time=5.90 ms
^C


[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2 //這是為了確保docker順利安裝好所必需的依賴包
如果在這一步報錯。就新增一下源。
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@localhost ~]# yum install epel-release


[root@localhost ~]# yum install container-selinux //照做就行


安裝docker-ce
[root@localhost ~]# yum clean all //清理軟體源
已載入外掛:fastestmirror, langpacks
正在清理軟體源: base epel extras updates zabbix zabbix-non-supported
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors

[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo //照著敲就行

[root@localhost ~]# yum makecache fast //生成元資料快取

[root@localhost ~]# yum -y install docker-ce //安裝docker-ce (社群版)

[root@localhost ~]# systemctl start docker.service //啟動docker


[root@localhost ~]# systemctl enable docker.service //設定docker的開機自啟動
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]#

[root@localhost ~]# ifconfig //這個時候注意看,多了一個docker0,代表docker安裝成功
**docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500**
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:86:be:21:47 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.4 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::617f:ef93:80d4:e14e prefixlen 64 scopeid 0x20<link>
inet6 240e:3a2:745:8d30:ea90:dfb7:2133:6e48 prefixlen 64 scopeid 0x0<global>
ether 00:0c:29:87:af:a6 txqueuelen 1000 (Ethernet)
RX packets 456859 bytes 309622054 (295.2 MiB)
RX errors 0 dropped 235 overruns 0 frame 0
TX packets 146203 bytes 12224280 (11.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 1867 bytes 164060 (160.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1867 bytes 164060 (160.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:8e:d3:64 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@localhost ~]# docker version //檢視docker的版本號,也可以證實docker已經成功安裝
Client: Docker Engine - Community
Version: 20.10.10
API version: 1.41
Go version: go1.16.9
Git commit: b485636
Built: Mon Oct 25 07:44:50 2021
OS/Arch: linux/amd64
Context: default
Experimental: true

Server: Docker Engine - Community
Engine:
Version: 20.10.10
API version: 1.41 (minimum version 1.12)
Go version: go1.16.9
Git commit: e2f740d
Built: Mon Oct 25 07:43:13 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.11
GitCommit: 5b46e404f6b9f661a205e28d59c982d3634148f8
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0

注意事項:1.一條一條按照我上面寫的命令來敲,就可以完成docker的安裝。
2. docker在安裝的過程當中,我們要讓伺服器本身能夠上網。
3. Darker在使用的過程當中,這些本身也要能夠上網。因為docker服務大多數都是基於映象而做出的操作。因此,Docker映象的拉血,用需要訪問公網。對我們的伺服器必須能夠上網。