在前面的文章中系統的介紹了Docker鏡像的管理以及Docker中容器的管理,和使用Dockerfile來針對主流程式語言的環境部署。下面詳細的概述下Docker中鏡像的發布以及Docker中鏡像發布的詳細過程。
首先在https://hub.docker.com/地址註冊一個帳戶。如果想把自己的鏡像發布到dockerhub的地址,那麼鏡像的名稱必須是name/imageName如image的名稱為hello 那麼要發布的鏡像名稱就為:wuyashare/hello,如果不這樣處理的話,進行push的時候,就會提示沒有權限的操作,這點需要特別的注意。下面詳細的演示發布鏡像的過程,具體如下:
#登錄到dockerhub
[root@wuyaShare ~]# docker login
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
#查看已打包的鏡像文件
[root@wuyaShare ~]# docker image ls | grep flask
flask_web latest a729b9e871d5 20 hours ago 481MB
#修改鏡像文件為符合push的名稱
[root@wuyaShare ~]# docker tag a729b9e871d5 wuyashare/book
[root@wuyaShare ~]# docker image ls | grep book
wuyashare/book latest a729b9e871d5 20 hours ago 481MB
#發布鏡像到dockerhub
[root@wuyaShare ~]# docker push wuyashare/book:latest
The push refers to repository [docker.io/wuyashare/book]
18a0c85cec57: Pushed
ccddeef0e471: Pushed
0aa6da94c8d9: Pushed
bf30ad1ae062: Pushed
3f731ba12c3e: Pushed
aed45bc432f2: Pushed
703c251de224: Pushed
36f20b3f9e91: Pushed
fb82b029bea0: Mounted from library/centos
latest: digest: sha256:56a92f3d696e0ac4d49746a63d2c6f384357670d7eb2011c3653509a9c6b0e84 size: 2204
下來到自己的dockerhub的主頁,就可以看到發布的鏡像信息了,具體如下所示:
當然下來就可以獲取自己發布的鏡像了,具體如下所示:
#從dockerhub獲取鏡像信息
[root@wuyaShare ~]# docker pull wuyashare/book
Using default tag: latest
latest: Pulling from wuyashare/book
9b4ebb48de8d: Already exists
a9c452da1e09: Pull complete
c3b21741ca1e: Pull complete
2daa5f93af93: Pull complete
99a143663da8: Pull complete
6ddb7dd30ad9: Pull complete
86969619219d: Pull complete
26db951a2c92: Pull complete
8757f98f9b66: Pull complete
Digest: sha256:56a92f3d696e0ac4d49746a63d2c6f384357670d7eb2011c3653509a9c6b0e84
Status: Downloaded newer image for wuyashare/book:latest
docker.io/wuyashare/book:latest
#運行鏡像
[root@wuyaShare ~]# docker run -it --rm wuyashare/book:latest
* Serving Flask app 'app' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://172.18.0.2:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 105-275-560
#獲取運行的容器ID的信息
docker ps -a | grep book
b13de0ca638f wuyashare/book:latest "python3 app.py" 2 minutes ago Up About a minute 5000/tcp focused_pasteur
#進入正在運行的容器
[root@wuyaShare ~]# docker exec -it b13de0ca638f bash
[root@b13de0ca638f opt]# ls
app.py
[root@b13de0ca638f opt]#
如上,可以看到,我們通過Dockerfile構建一個鏡像後,可以把鏡像文件發布到dockerhub中,這樣不管是自己還是其他的人員都是可以獲取這個鏡像文件,然後對它進行運行,從而提供具體的服務。比如您編寫了一個測試的工具,想讓別人使用它,那麼可以發布成鏡像,然後對鏡像運行後,這樣直接可以運行,而對方不需要刻意搭建運行這個測試工具的環境。感謝您的閱讀,後續會持續的進行更新。