1.根據運行的容器制作鏡像
1
2
|
#查看所有的容器 docker ps |
1
2
|
#暫停當前容器 docker pause cotnainer- id |
1
2
|
#將容器運行當前狀態提交 docker commit cotnainer- id |
1
2
|
#根據commit-id打包容器tag docker tag commit- id |
經過以上幾個步驟,根據當前運行的容器制作鏡像就完成了。
2.上傳鏡像到docker hub
如果未登錄docker hub,需要登錄docker hub
1
2
|
docker login #輸入用戶名和密碼 |
推送鏡像到docker hub
1
|
docker push image-name |
運行結果如下圖所示:
在docker hub上可以查看到我們剛剛上傳的鏡像文件,因為這個鏡像是公開的,所以現在所有人都能夠docker pull獲取該鏡像。
3.獲取上傳的鏡像并運行
因為我使用的是同一臺ubuntu機器,我本地已經有了bage88/firstimage
這個鏡像,我先要刪除該鏡像,然后再獲取。
3.1 刪除鏡像
1
2
|
#### 刪除鏡像 docker rmi image_name |
提示如下錯誤,有基于該鏡像的容器在運行,所以我先要刪除這個容器,再刪除鏡像。
1
2
|
error response from daemon: conflict: unable to remove repository reference "bage88/firstimage" (must force) - container 25dca6040e7e is using its referenced image 31758d7d9e60 |
3.2 刪除容器
1
|
docker rm 25dca6040e7e(這個是容器 id ) |
再執行一次刪除鏡像命令:
1
2
3
4
5
6
7
|
docker rmi bage88 /firstimage ###結果如下,說明刪除鏡像成功 untagged: bage88 /firstimage :latest untagged: bage88 /firstimage @sha256:dc8a6511903cdcd25cf2d9de76a1c9ba21c050bb7702525fb3e1ba0168071481 deleted: sha256:31758d7d9e60b3c77bad4f477faae5e9dc87d3d5d16a085263f2f6de58a381ad deleted: sha256:77757027951c22c480289ef98c6109c6d7df4e0bae9bda5db1e43436159de9e5 |
3.3 獲取鏡像
1
|
docker pull bage88 /firstimage |
3.4 運行鏡像
1
|
docker run -d -p 8010:80 bage88 /firstimage |
查看結果:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://www.cnblogs.com/liminjun88/p/6839198.html?utm_source=tuicool&utm_medium=referral