centos7搭建基礎docker

陳十一yi發表於2021-01-05


條件:需要XianDian-PaaS-v2.1映象,IP:192.168.131.116

配置網路

[root@localhost ~]# nmcli connection modify "ens33" ipv4.method manual ipv4.addresses "192.168.131.116/24" ipv4.gateway "192.168.131.2" ipv4.dns "114.114.114.114" connection.autoconnect yes

[root@localhost ~]# nmcli con down ens33
[root@localhost ~]# nmcli con up   ens33

[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (36.152.44.95) 56(84) bytes of data.
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=1 ttl=128 time=51.3 ms
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=2 ttl=128 time=36.9 ms

配置本地yum源

掛載XianDian-PaaS-v2.1映象

在這裡插入圖片描述
在這裡插入圖片描述
在這裡插入圖片描述
在這裡插入圖片描述

##使用XianDian-PaaS-v2.1映象作為本地yum源
[root@localhost ~]# mount /dev/sr0 /mnt/
[root@localhost ~]# cp -rvf /mnt/* /opt/centos/

#建立本地yum源目錄
[root@localhost ~]# mkdir /opt/centos/

#先移除yum.repos.d原先的repo檔案,然後建立新的repo檔案
[root@localhost ~]# mkdir /etc/yum.repos.d/bak
[root@localhost ~]# mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/bak/
[root@localhost ~]# vim /etc/yum.repos.d/docker.repo
					[docker]
					name=docker
					baseurl=file:///opt/centos/docker
					gpgcheck=0
					enabled=1

關閉防火牆及SELinux

[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# systemctl disable firewalld.service 

[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config 
					SELINUX=disabled

修改防火牆規則

[root@localhost ~]# iptables -F
[root@localhost ~]# iptables -X
[root@localhost ~]# iptables -Z
[root@localhost ~]# /usr/sbin/iptables-save

開啟核心轉發功能

##在檔案中新增如下三行
[root@localhost ~]# vim /etc/sysctl.conf 
					net.ipv4.ip_forward = 1
					net.ipv4.conf.default.rp_filter = 0
					net.ipv4.conf.all.rp_filter = 0

[root@localhost ~]# sysctl -p

查詢yum列表

[root@localhost ~]# yum clean all;yum repolist 
Loaded plugins: fastestmirror, langpacks
Cleaning repos: docker
Cleaning up list of fastest mirrors
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
docker                                                                                                         | 2.9 kB  00:00:00     
docker/primary_db                                                                                              |  58 kB  00:00:00     
repo id                                                         repo name                                                       status
docker                                                          docker                                                          59
repolist: 59
[root@localhost ~]# 

安裝服務

yum install -y docker-io

配置倉庫地址並啟動服務

##在配置檔案中新增如下命令
[root@localhost ~]# vim /etc/sysconfig/docker
					ADD_REGISTRY='--add-registry 192.168.131.116:5000' 
					INSECURE_REGISTRY='--insecure-registry 192.168.131.116:5000'
##啟動服務及開機自啟
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker

搭建docker私有倉庫

[root@localhost ~]# cd /opt/centos/docker_images/

##倉庫映象下載
[root@localhost docker_images]# docker load <registry_latest.tar

##建立倉庫容器
[root@localhost docker_images]# docker run  -d -p 5000:5000 --restart=always --name registry docker.io/registry:latest

##查詢映象
[root@localhost docker_images]# docker images 
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
docker.io/registry   latest              c9bd19d022f6        4 years ago         33.27 MB

##打上私有倉庫標籤
[root@localhost docker_images]# docker tag  c9bd19d022f6	192.168.131.116:5000/registry:latest

##將本地映象上傳至私有庫
[root@localhost docker_images]# docker push  192.168.131.116:5000/registry:latest
The push refers to a repository [192.168.131.116:5000/registry]

部署docker-server節點

##下載映象
[root@localhost docker_images]# docker load <rancher_server_v1.1.4-xd.tar

##檢視映象
[root@localhost docker_images]# docker images 
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
<none>                          <none>              85065a46e1f3        3 years ago         917.7 MB
192.168.131.116:5000/registry   latest              c9bd19d022f6        4 years ago         33.27 MB
docker.io/registry              latest              c9bd19d022f6        4 years ago         33.27 MB

##打標籤
[root@localhost docker_images]# docker tag 85065a46e1f3 192.168.131.116:5000/rancher/server:v1.1.4-xd

##上傳映象至私有庫
[root@localhost docker_images]# docker push 192.168.131.116:5000/rancher/server:v1.1.4-xd 
The push refers to a repository [192.168.131.116:5000/rancher/server]##執行容器
[root@localhost docker_images]# docker run -d --restart=always -p 80:8080 rancher/server:v1.1.4-xd
120510f9180de11878c65d0ab46b302c6cf0eb21627c0a3b1574bdf684024c6c

##查詢容器
[root@localhost docker_images]# docker ps -a
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                            NAMES
120510f9180d        rancher/server:v1.1.4-xd    "/usr/bin/s6-svscan /"   8 seconds ago       Up 7 seconds        3306/tcp, 0.0.0.0:80->8080/tcp   berserk_wilson
e10f90068780        docker.io/registry:latest   "/entrypoint.sh /etc/"   39 minutes ago      Up 39 minutes       0.0.0.0:5000->5000/tcp           registry
[root@localhost docker_images]# 

部署docker-client節點

##下載相關映象
[root@localhost docker_images]# docker load <rancher_agent_v1.0.2.tar
Error response from daemon: invalid argument
[root@localhost docker_images]# docker load <rancher_agent-instance_v0.8.3.tar
Error response from daemon: invalid argument
[root@localhost docker_images]# 


##查詢映象
[root@localhost docker_images]# docker images 
REPOSITORY                            TAG                 IMAGE ID            CREATED             SIZE
192.168.131.116:5000/rancher/server   v1.1.4-xd           85065a46e1f3        3 years ago         917.7 MB
192.168.131.116:5000/registry         latest              c9bd19d022f6        4 years ago         33.27 MB
docker.io/registry                    latest              c9bd19d022f6        4 years ago         33.27 MB
<none>                                <none>              6dccaa66a75d        4 years ago         330.9 MB
<none>                                <none>              deb5c6987c83        4 years ago         454.3 MB
[root@localhost docker_images]# 


##為映象打上私有倉庫標籤
[root@localhost docker_images]# docker tag deb5c6987c83   192.168.131.116:5000/rancher/agent:v1.0.2
[root@localhost docker_images]# docker tag 6dccaa66a75d  192.168.131.116:5000/rancher/agent-instance:v0.8.3

##將映象上傳到私有倉庫
[root@localhost docker_images]# docker push 192.168.131.116:5000/rancher/agent:v1.0.2 
The push refers to a repository [192.168.131.116:5000/rancher/agent]
[root@localhost docker_images]# docker push 192.168.131.116:5000/rancher/agent-instance:v0.8.3 
The push refers to a repository [192.168.131.116:5000/rancher/agent-instance]


檢視私有倉庫的映象

在這裡插入圖片描述

頁面訪問

在這裡插入圖片描述

相關文章