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

相关文章

文章浏览阅读8.8k次,点赞2次,收藏7次。本文介绍Docker Com...
文章浏览阅读1.5w次,点赞7次,收藏76次。原网提供的教程需要...
文章浏览阅读940次,点赞20次,收藏20次。通过 docker run 命...
文章浏览阅读1k次,点赞20次,收藏20次。Podman 是一个开源的...
文章浏览阅读2.1k次。请注意,这些命令需要在 Docker 主机上...
文章浏览阅读1.1k次,点赞37次,收藏40次。nacos搭建集群连接...