随笔 - 308  文章 - 0  评论 - 84  阅读 - 75万

docker镜像打包,上传

docker镜像打包

前言

docker打包镜像

简单栗子

使用nginx打包一个静态页面的镜像

测试的代码地址[https://github.com/boilingfrog/daily-test/tree/master/docker-images/test]

1、制作dockerfile

FROM nginx

COPY test /usr/share/nginx/html

2、打包镜像

docker build -t test-static ./test

结果

$ docker build -t test-static ./test
Sending build context to Docker daemon  9.728kB
Step 1/2 : FROM nginx
 ---> 4bb46517cac3
Step 2/2 : COPY test /usr/share/nginx/html
 ---> fc981d4aa54c
Successfully built fc981d4aa54c
Successfully tagged test-static:latest

test-static表示打包成的镜像名,./test打包镜像代码地址

3、镜像打上tag

如果我要上传的地址是https://hub.docker.com/,把tag打成你在https://hub.docker.com/注册的用户名加镜像的命名就好了

 docker tag test-static:latest liz2019/test-static

当然后面也是可以加上版本,如果不加就是默认的latest

 docker tag test-static:latest liz2019/test-static:v1

如果希望上传到自己的搭建的仓库,那么只需加上自己的仓库地址就好了

 docker tag test-static:latest hub.xxx.com/xxx/test-static:v1

4、上传到仓库

直接push刚打完tag的镜像就好了,上传到https://hub.docker.com/是需要登录的。

docker push liz2019/test-static

结果

$ docker push liz2019/test-static
The push refers to repository [docker.io/liz2019/test-static]
525ddb970a89: Pushed 
550333325e31: Mounted from liz2019/docker-file-image 
22ea89b1a816: Mounted from liz2019/docker-file-image 
a4d893caa5c9: Mounted from liz2019/docker-file-image 
0338db614b95: Mounted from liz2019/docker-file-image 
d0f104dc0a1f: Mounted from liz2019/docker-file-image 
latest: digest: sha256:53e8eb1dc6749f05cd303a13588584f9944b6f66b25b8914c49923a16c1ba6b2 size: 1569

成功了

最后运行下docker run -p 8000:80 test-static

posted on   ZhanLi  阅读(1055)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
历史上的今天:
2018-08-20 go中的make和new的区别
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示