解決http協定的問題:
方法一:解決HTTPS問題
安裝nginx,配置HTTPS協定
方法二:修改docker的配置檔案
vim /etc/default/docker增加
OPTIONS="--insecure-registry 192.168.10.249:5000"
準備配置環境:
主機名 | 主機IP | 服務 |
docker-p_w_picpaths | 10.0.0.5 | docker 私有庫庫配置 |
10.0.0.6 | docker 用戶端 |
[root@docker-p_w_picpaths ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@docker-p_w_picpaths ~]# uname -r
3.10.0-327.el7.x86_64
[root@docker-p_w_picpaths ~]# uname -m
x86_64
[root@docker-p_w_picpaths ~]# uname -a
Linux docker-p_w_picpaths 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@docker-p_w_picpaths ~]#
開始配置(鏡像庫)
1、關閉防火牆和selinux
[root@docker-p_w_picpaths ~]# systemctl stop firewalld
[root@docker-p_w_picpaths ~]# systemctl disable firewalld #永久
[root@docker-p_w_picpaths ~]# setenforce 0
[root@docker-p_w_picpaths ~]# getenforce
Permissive
[root@docker-p_w_picpaths ~]#
2、安裝docker
yum install docker
[root@docker-p_w_picpaths ~]# systemctl enable docker #加入開機自啟動
[root@docker-p_w_picpaths ~]# systemctl start docker #開啟服務
3、下載下傳本地私有庫registry
[root@docker-p_w_picpaths ~]# docker pull registry #預設下載下傳最新版
[root@docker-p_w_picpaths ~]# docker p_w_picpaths #檢視下載下傳的鏡像
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 047218491f8c 10 days ago 33.17 MB
[root@docker-p_w_picpaths ~]#
4、基于私有倉庫鏡像運作容器
[root@docker-p_w_picpaths ~]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry docker.io/registry
#預設倉庫建立在/tmp/registry,用-v參數指定倉庫存放位置
1e8b1a03013ee66034b40aee1820000a2ccf026a3b1e43606f3e4007b2a9d455
[root@docker-p_w_picpaths ~]#
[root@docker-p_w_picpaths ~]# docker ps #檢視運作容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e8b1a03013e docker.io/registry "/entrypoint.sh /etc/" 35 seconds ago Up 32 seconds 0.0.0.0:5000->5000/tcp goofy_mcnulty
[root@docker-p_w_picpaths ~]#
5、通路私有倉庫
[root@docker-p_w_picpaths ~]# curl 127.0.0.1:5000/v2
<a href="/v2/">Moved Permanently</a>.
[root@docker-p_w_picpaths ~]#
#說明registry部署成功
6、為基礎鏡像打标簽
[root@docker-p_w_picpaths ~]# docker search docker.io/fedora/ssh|grep docker.io/fedora/ssh
docker.io docker.io/fedora/ssh 20 [OK]
[root@docker-p_w_picpaths ~]# docker pull docker.io/fedora/ssh #下載下傳鏡像
[root@docker-p_w_picpaths ~]# docker p_w_picpaths
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 047218491f8c 10 days ago 33.17 MB
docker.io/fedora/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
[root@docker-p_w_picpaths ~]# docker tag docker.io/fedora/ssh 127.0.0.1:5000/ssh #打标簽
[root@docker-p_w_picpaths ~]# docker p_w_picpaths
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 047218491f8c 10 days ago 33.17 MB
127.0.0.1:5000/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
docker.io/fedora/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
[root@docker-p_w_picpaths ~]#
[root@docker-p_w_picpaths ~]# vim /etc/sysconfig/docker
OPTIONS="--selinux-enabled --insecure-registry 10.0.0.5:5000" #定制私有倉庫URL
[root@docker-p_w_picpaths ~]# systemctl restart docker
7、送出鏡像到本地私有庫
[root@docker-p_w_picpaths ~]# docker start 1e8 #開啟本地庫
1e8
[root@docker-p_w_picpaths ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e8b1a03013e docker.io/registry "/entrypoint.sh /etc/" 4 hours ago Up 3 seconds 0.0.0.0:5000->5000/tcp goofy_mcnulty
[root@docker-p_w_picpaths ~]#
[root@docker-p_w_picpaths ~]# docker push 127.0.0.1:5000/ssh #上傳打好标簽的庫
The push refers to a repository [127.0.0.1:5000/ssh]
482d621bda33: Pushed
510f15c27a8b: Pushed
e4f86288aaf7: Pushed
latest: digest: sha256:5ad5aec14bb7aa63fdcea1772db6ab5b5de99b0a023d234e61f5aa8c9435e8ff size: 948
[root@docker-p_w_picpaths ~]#
8、檢視已經上傳好的鏡像
[root@docker-p_w_picpaths ~]# curl 10.0.0.5:5000/v2/_catalog
{"repositories":["ssh"]}
[root@docker-p_w_picpaths ~]#
浏覽器中檢視已經上傳的鏡像
http://10.0.0.5:5000/v2/_catalog

9、測試庫是否可用,在準備好環境的另一台測試機上面下載下傳上傳的鏡像
[root@centos7 ~]# vim /etc/sysconfig/docker #加入私有倉庫位址
OPTIONS="--selinux-enabled --insecure-registry 10.0.0.5:5000"
[root@centos7 ~]# systemctl restart docker
[root@centos7 ~]# docker pull 10.0.0.5:5000/ssh
可以看到已經可以下載下傳鏡像,證明私有倉庫建立成功
[root@centos7 ~]# docker p_w_picpaths
REPOSITORY TAG IMAGE ID CREATED SIZE
10.0.0.5:5000/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
[root@centos7 ~]#
接下來通過自己的私有庫運作一個centos7容器
1、從其他的資料庫上save一個centos鏡像推送到私有庫伺服器上
[root@docker-p_w_picpaths ~]# ls
anaconda-ks.cfg centos.tar
[root@docker-p_w_picpaths ~]# docker load < centos.tar #将鏡像導入docker
34e7b85d83e4: Loading layer [==================================================>] 199.9 MB/199.9 MB
Loaded p_w_picpath: docker.io/centos:latest ] 557.1 kB/199.9 MB
[root@docker-p_w_picpaths ~]# docker p_w_picpaths
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 047218491f8c 10 days ago 33.17 MB
127.0.0.1:5000/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
docker.io/fedora/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
docker.io/centos latest 67591570dd29 12 weeks ago 191.8 MB
[root@docker-p_w_picpaths ~]#
2、再次打上自己的标簽
[root@docker-p_w_picpaths ~]# docker tag docker.io/centos:latest 10.0.0.5:5000/lcentos
#為了差別前面的,我将centos做了其他标記
[root@docker-p_w_picpaths ~]# docker p_w_picpaths
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 047218491f8c 10 days ago 33.17 MB
127.0.0.1:5000/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
docker.io/fedora/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
docker.io/centos latest 67591570dd29 12 weeks ago 191.8 MB
10.0.0.5:5000/lcentos latest 67591570dd29 12 weeks ago 191.8 MB
[root@docker-p_w_picpaths ~]#
3、上傳标記好的鏡像到自己的私有庫
[root@docker-p_w_picpaths ~]# docker push 10.0.0.5:5000/lcentos
4、檢視上傳好的鏡像
[root@docker-p_w_picpaths ~]# curl http://10.0.0.5:5000/v2/_catalog
{"repositories":["lcentos","ssh"]}
[root@docker-p_w_picpaths ~]#
浏覽器檢視
5、再次到準備好環境的那台測試機上面pull
[root@centos7 ~]# docker pull 10.0.0.5:5000/lcentos
[root@centos7 ~]# docker p_w_picpaths
REPOSITORY TAG IMAGE ID CREATED SIZE
10.0.0.5:5000/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
10.0.0.5:5000/lcentos latest 67591570dd29 12 weeks ago 191.8 MB
[root@centos7 ~]#
6、建立并運作一個容器
[root@centos7 ~]# docker run -d -it --privileged=false -p 80:80 --name abccentos 10.0.0.5:5000/lcentos /bin/bash
15b9f42b3d63846085664139bff0c041f614bc2b717787686d23785d98b37160
[root@centos7 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15b9f42b3d63 10.0.0.5:5000/lcentos "/bin/bash" 16 seconds ago Up 13 seconds 0.0.0.0:80->80/tcp abccentos
[root@centos7 ~]#
7、進入容器檢視,可以看到centos的版本等資訊
[root@centos7 ~]# docker attach 15b9f42b3d63
[root@15b9f42b3d63 /]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@15b9f42b3d63 /]# uname -r
3.10.0-327.el7.x86_64
[root@15b9f42b3d63 /]# uname -a
Linux 15b9f42b3d63 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@15b9f42b3d63 /]#
8、還可以在此作業系統中安裝部署nginx。
[root@15b9f42b3d63 yum.repos.d]# yum -y install wget #安裝wget,友善安裝epel源
[root@15b9f42b3d63 yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@15b9f42b3d63 yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo
[root@15b9f42b3d63 yum.repos.d]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@15b9f42b3d63 yum.repos.d]# yum clean all
[root@15b9f42b3d63 yum.repos.d]# yum makecache
[root@15b9f42b3d63 yum.repos.d]# yum -y install nginx
[root@15b9f42b3d63 yum.repos.d]# rpm -qa|grep nginx
nginx-filesystem-1.10.2-1.el7.noarch
nginx-mod-http-xslt-filter-1.10.2-1.el7.x86_64
nginx-mod-mail-1.10.2-1.el7.x86_64
nginx-mod-stream-1.10.2-1.el7.x86_64
nginx-mod-http-perl-1.10.2-1.el7.x86_64
nginx-mod-http-geoip-1.10.2-1.el7.x86_64
nginx-mod-http-p_w_picpath-filter-1.10.2-1.el7.x86_64
nginx-1.10.2-1.el7.x86_64
nginx-all-modules-1.10.2-1.el7.noarch
[root@15b9f42b3d63 yum.repos.d]#
9、檢視服務
[root@15b9f42b3d63 yum.repos.d]# nginx #開啟服務
[root@15b9f42b3d63 yum.repos.d]# ps -ef|grep nginx
root 143 1 0 20:48 ? 00:00:00 nginx: master process nginx
nginx 144 143 0 20:48 ? 00:00:00 nginx: worker process
nginx 145 143 0 20:48 ? 00:00:00 nginx: worker process
nginx 146 143 0 20:48 ? 00:00:00 nginx: worker process
nginx 147 143 0 20:48 ? 00:00:00 nginx: worker process
root 153 1 0 20:49 ? 00:00:00 grep --color=auto nginx
10、檢視端口
[root@15b9f42b3d63 /]# netstat -lntup|grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 20/nginx: master pr
tcp6 0 0 :::80 :::* LISTEN 20/nginx: master pr
[root@15b9f42b3d63 /]#
11、浏覽器通路