Docker-安裝私服
在使用maven管理jar包依賴的時候,為了避免每次都從中央倉庫拉取依賴包,使用了nexus做了代理倉庫。docker映象倉庫與nexus私服倉庫作用類似,用於將打包好的映象儲存在倉庫中方便開發、測試、生產環境映象拉取儲存,減輕環境部署需要的相應操作。
1.1 購買阿里雲伺服器
1、選擇雲伺服器,建立例項
2、自定義購買,按量付費
3、選擇伺服器型別,數量,記憶體,頻寬
4、自定義登入密碼
5、建立成功!!!
1.2 節點資訊
購買兩個伺服器,伺服器的名字為root
,伺服器密碼: Hxy162530
。
主機名 | ip地址 | 具體說明 |
---|---|---|
guardwhy01 | 8.134.117.200 | docker主機 |
guardwhy02 | 8.134.113.78 | registry主機 |
1.3 官方私服
1、映象官方地址: https://hub.docker.com/_/registry
2、基礎映象
拉取基本映象
docker pull registry:2.7.1
執行容器
docker run -itd --name gegistry -p 5000:5000 --restart always registry:2.7.1
訪問連結: http://8.134.113.78:5000/v2/_catalog
3、新增私服倉庫地址
編輯配置檔案 vim /etc/docker/daemon.json 增加倉庫配置資訊 { "insecure-registries":["8.134.113.78:5000"] } 重啟docker systemctl daemon-reload systemctl restart docker 檢視docker資訊確認倉庫是否新增 docker info
4、上傳映象
docker tag nginx:1.20.1 8.134.113.78:5000/nginx:v1
docker push 8.134.113.78:5000/nginx:v1
5、檢視映象版本和資訊
6、從官方私服中下載映象
[root@guardwhy01 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE [root@guardwhy01 ~]# docker pull 8.134.113.78:5000/nginx:v1 v1: Pulling from nginx 69692152171a: Pull complete 94d185f62f0a: Pull complete da9d3d3df3e3: Pull complete 1c11b8f3980d: Pull complete 541b1d41bb91: Pull complete d8f6ef04dfa8: Pull complete Digest: sha256:56cbb3c9ada0858d69d19415039ba2aa1e9b357ba9aa9c88c73c30307aae17b0 Status: Downloaded newer image for 8.134.113.78:5000/nginx:v1 8.134.113.78:5000/nginx:v1 [root@guardwhy01 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 8.134.113.78:5000/nginx v1 993ef3592f66 3 weeks ago 133MB [root@guardwhy01 ~]#
1.4 企業私服
1.4.1 安裝私服
1、購買2核8G記憶體伺服器,安裝docker
和docker compose
2、下載harbor
官方地址: https://goharbor.io/
github官網地址:https://github.com/goharbor/harbor
官方幫助文件:https://github.com/goharbor/harbor/blob/v1.9.4/docs/installation_guide.md
3、伺服器配置
硬體資源 | 最小配置 | 推薦配置 |
---|---|---|
CPU | 2CPU | 4CPU |
記憶體 | 4GB | 8GB |
硬碟 | 40GB | 60GB |
4、安裝harbor開發環境大部分採用http方式進行安裝,推薦使用離線安裝!!!
通過Xftp
上傳到\home\data
目錄中,然後解壓軟體。
[root@guardwhy03 data]# ls
harbor-offline-installer-v1.9.4.tgz
[root@guardwhy03 data]# tar zxvf harbor-offline-installer-v1.9.4.tgz
harbor/harbor.v1.9.4.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/harbor.yml
[root@guardwhy03 data]# ll
total 624500
drwxr-xr-x 2 root root 4096 Jun 17 21:53 harbor
-rw-r--r-- 1 root root 639477963 Jun 17 21:11 harbor-offline-installer-v1.9.4.tgz
5、進入安裝目錄,修改 harbor.yml
檔案
修改私服映象地址
hostname: 8.134.123.77
修改映象地址訪問埠號
port: 5000
harbor管理員登入系統密碼
harbor_admin_password: Harbor12345
修改harbor對映卷目錄
data_volume: /home/data/harbor
5、安裝harbor
執行啟動指令碼
./install.sh
準備安裝環境:檢查docker版本和docker-compose版本
安裝成功!!!
6、使用Chrome 瀏覽器訪問harbor私服,點選連結: http://8.134.123.77:5000/harbor/projects,輸入使用者名稱和預設的密碼
1.4.2 上傳映象
1、在主機docker01
中配置私服。
[root@guardwhy01 data]# vim /etc/docker/daemon.json
[root@guardwhy01 data]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://5bsomu6l.mirror.aliyuncs.com"],
"insecure-registries":["8.134.123.77:5000"]
}
## 重啟docker服務!!!
[root@guardwhy01 data]# systemctl daemon-reload
[root@guardwhy01 data]# systemctl restart docker
2、在harbor
介面中新建專案:guardwhy_cms
3、登入和退出私服
## 登入私服
docker login -u admin -p Harbor12345 8.134.123.77:5000
## 退出私服
docker logout 8.134.123.77:5000
檢視當前映象
[root@guardwhy01 data]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx 1.20.1 993ef3592f66 3 weeks ago 133MB
tomcat 9.0.20-jre8-alpine 387f9d021d3a 2 years ago 108MB
4、上傳映象
docker tag nginx:1.20.1 8.134.123.77:5000/guardwhy_cms/nginx:v1.0
docker tag tomcat:9.0.20-jre8-alpine 8.134.123.77:5000/guardwhy_cms/tomcat:v1.0
## 推送操作
docker push 8.134.123.77:5000/guardwhy_cms/nginx:v1.0
docker push 8.134.123.77:5000/guardwhy_cms/tomcat:v1.0
檢視映象
上傳映象成功!!
5、通過私服下載映象,下載成功!!!
[root@guardwhy01 data]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@guardwhy01 data]# docker pull 8.134.123.77:5000/guardwhy_cms/nginx:v1.0
v1.0: Pulling from guardwhy_cms/nginx
69692152171a: Pull complete
94d185f62f0a: Pull complete
da9d3d3df3e3: Pull complete
1c11b8f3980d: Pull complete
541b1d41bb91: Pull complete
d8f6ef04dfa8: Pull complete
Digest: sha256:56cbb3c9ada0858d69d19415039ba2aa1e9b357ba9aa9c88c73c30307aae17b0
Status: Downloaded newer image for 8.134.123.77:5000/guardwhy_cms/nginx:v1.0
8.134.123.77:5000/guardwhy_cms/nginx:v1.0
[root@guardwhy01 data]# docker pull 8.134.123.77:5000/guardwhy_cms/tomcat:v1.0
v1.0: Pulling from guardwhy_cms/tomcat
e7c96db7181b: Pull complete
f910a506b6cb: Pull complete
b6abafe80f63: Pull complete
d8c966ddef98: Pull complete
15b754e99755: Pull complete
4227393eb352: Pull complete
Digest: sha256:490b98379033031e84f9795da326371fdb95c6d9c3f5e3c14e1316ca754e324f
Status: Downloaded newer image for 8.134.123.77:5000/guardwhy_cms/tomcat:v1.0
8.134.123.77:5000/guardwhy_cms/tomcat:v1.0
[root@guardwhy01 data]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
8.134.123.77:5000/guardwhy_cms/nginx v1.0 993ef3592f66 3 weeks ago 133MB
8.134.123.77:5000/guardwhy_cms/tomcat v1.0 387f9d021d3a 2 years ago 108MB
[root@guardwhy01 data]#