「Spring Boot」 推送Docker映象到阿里雲映象服務
阿新 • • 發佈:2018-12-21
容器映象服務(Container Registry)提供安全的應用映象託管能力,精確的映象安全掃描功能,穩定的映象構建服務,便捷的映象授權功能,方便使用者進行映象全生命週期管理。容器映象服務簡化了Registry的搭建運維工作,支援多地域的映象託管,並聯合容器服務等雲產品,打造雲上使用Docker的一體化體驗。
新建SpringBoot應用並配置DockerFile
修改配置檔案application.properties
server.port= 8099
開通阿里映象服務
訪問https://dev.aliyun.com/search.html
進入管理中心
建立名稱空間
設定Registry登入密碼,非阿里雲登入密碼
第一次建立會出現教程,和github 剛建立專案一樣,會告知如果推送
推送映象
登入阿里雲Docker Registry
$ docker login --username=134******[email protected] registry.cn-hangzhou.aliyuncs.com
$ Password:
$ Login Succeeded
將映象推送到Registry
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
aprcode/spring-boot-docker-aliyun latest 671bc04fb203 17 minutes ago 119MB
openjdk 8-jdk-alpine 97bc1352afde 2 weeks ago 103MB
$ docker tag 671bc04fb203 registry.cn-hangzhou.aliyuncs.com/aprcode/aprcode:aprcode.1.0.0
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
aprcode/spring-boot-docker-aliyun latest 671bc04fb203 19 minutes ago 119MB
registry.cn-hangzhou.aliyuncs.com/aprcode/aprcode aprcode.1.0.0 671bc04fb203 19 minutes ago 119MB
openjdk 8-jdk-alpine 97bc1352afde 2 weeks ago 103MB
$ docker push registry.cn-hangzhou.aliyuncs.com/aprcode/aprcode:aprcode.1.0.0
The push refers to repository [ registry.cn-hangzhou.aliyuncs.com/aprcode/aprcode]
5c52652cc20a: Pushed
ed6f0bd39121: Layer already exists
0c3170905795: Layer already exists
df64d3292fd6: Layer already exists
aprcode.1.0.0: digest: sha256:88df67826b192791332ee79659f091634f04764d6c3d0feacc5dfd0c8cab2333 size: 1159
因為我之前推送了一個,所以顯示已存在, 不影響。
拉取映象並啟動
推送成功後可以在任何一個地方登入你的倉庫拉取映象了,接下來我登入我的阿里輕量應用伺服器拉取我們推送的映象,並啟動。伺服器已安裝Docker
登入伺服器
$ ssh [email protected]***** -p 22
[email protected]******'s password:
Last failed login: Wed Nov 14 10:54:19 CST 2018 from 59.173.241.186 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Wed Nov 14 08:41:08 2018 from 59.173.241.186
Welcome to Alibaba Cloud Elastic Compute Service !
[[email protected] ~]#
登入阿里雲Docker Registry
[[email protected] ~]# docker login --username=134******[email protected] registry.cn-hangzhou.aliyuncs.com
Password:
Login Succeeded
從Registry中拉取映象
[[email protected] ~]# docker pull registry.cn-hangzhou.aliyuncs.com/aprcode/aprcode:aprcode.1.0.0
aprcode.1.0.0: Pulling from aprcode/aprcode
4fe2ade4980c: Already exists
6fc58a8d4ae4: Already exists
ef87ded15917: Already exists
df60cf9e6a56: Pull complete
Digest: sha256:88df67826b192791332ee79659f091634f04764d6c3d0feacc5dfd0c8cab2333
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/aprcode/aprcode:aprcode.1.0.0
[[email protected] ~]#
啟動映象
將80埠對映到內網8099 埠上
[[email protected] ~]# docker run -d -p 80:8099 671bc04fb203
d38062b4eb07a40f6a80ac28c4ec38d992bc534fd7645a34401e3dfb67492b92
[[email protected] ~]#
訪問 http://www.aprcode.com/
歡迎關注我的公眾號,跟我留言。