亲注册登录道勤网-可以查看更多帖子内容哦!(包涵精彩图片、文字详情等)请您及时注册登录-www.daoqin.net
您需要 登录 才可以下载或查看,没有账号?立即注册
x
之前的实战中,我们实战中,我们使用的镜像都是镜像仓库已有的镜像。 已有的镜像都是别人已经开发好上传的。今天我们一起来看看如何构建自己的镜像并上传到镜像仓库中。 一. 设置docker构建镜像的环境1.1 commit 命令的介绍我们执行 docker help commit来查看: - [root@mufeng63 ~]# docker help commit
- Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
- Create a new image from a container's changes
- Aliases:
- docker container commit, docker commit
- Options:
- -a, --author string Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
- -c, --change list Apply Dockerfile instruction to the created image
- -m, --message string Commit message
- -p, --pause Pause container during commit (default true)
- [root@mufeng63 ~]#
复制代码 1.2 创建一个tomcat容器- 拉取Tomcat的镜像
- [root@mufeng63 ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- [root@mufeng63 ~]# docker pull tomcat
- Using default tag: latest
- latest: Pulling from library/tomcat
- 0e29546d541c: Pull complete
- 9b829c73b52b: Pull complete
- cb5b7ae36172: Pull complete
- 6494e4811622: Pull complete
- 668f6fcc5fa5: Pull complete
- dc120c3e0290: Pull complete
- 8f7c0eebb7b1: Pull complete
- 77b694f83996: Pull complete
- 0f611256ec3a: Pull complete
- 4f25def12f23: Pull complete
- Digest: sha256:9dee185c3b161cdfede1f5e35e8b56ebc9de88ed3a79526939701f3537a52324
- Status: Downloaded newer image for tomcat:latest
- docker.io/library/tomcat:latest
- [root@mufeng63 ~]#
复制代码
- 基于Tomcat的镜像创建容器
- [root@mufeng63 ~]# docker run --name mytomcat -d -p 8080:8080 tomcat
- 1f5bd6dcca0a614ec047bf3882e3fe2e4cdb17b7f343d7834145b17d1fc3c3c3
- [root@mufeng63 ~]#
复制代码
如果不创建页面,直接访问Tomcat是会报错的,所以这里需要手动创建一个web测试页面: - //查看正在运行的容器
- [root@mufeng63 ~]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 1f5bd6dcca0a tomcat "catalina.sh run" 53 seconds ago Up 52 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp mytomcat
- // 登录Tomcat容器
- [root@mufeng63 ~]# docker exec -it 1f5bd6dcca0a /bin/bash
- root@1f5bd6dcca0a:/usr/local/tomcat# ls
- BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp webapps.dist
- CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps work
- // 创建web测试目录
- root@1f5bd6dcca0a:/usr/local/tomcat# mkdir webapps/mufeng_demo
- //创建index.html
- root@1f5bd6dcca0a:/usr/local/tomcat# echo "<h1>This is mufenggrow </>" > webapps/mufeng_demo/index.html
- root@1f5bd6dcca0a:/usr/local/tomcat#
复制代码
执行完成后,看到多了一个mufeng_tomcat 的镜像。 三. 上传镜像到镜像仓库3.1 登录docker hubdocker hub的官网地址: https://hub.docker.com/
你可以手动创建存储库,当然也可以不创建,我们这里默认是不创建的,上传的时候直接用mufenggrow/ 即可
3.2 创建镜像如果要上传到镜像仓库中,需要在镜像名称前加上仓库的路径信息: - [root@mufeng63 ~]# docker commit 1f5bd6dcca0a mufenggrow/mufeng_tomcat
- sha256:dc9420341e4bd06cdd7dc5881220481c9dbe8faf4d548356c6dbab265a36416b
- [root@mufeng63 ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- mufenggrow/mufeng_tomcat latest dc9420341e4b 5 seconds ago 680MB
- mufeng_tomcat latest 3dbdf1f915ac 16 minutes ago 680MB
- tomcat latest fb5657adc892 15 months ago 680MB
复制代码 3.3 上传到镜像仓库- 使用docker login 登录
- [root@mufeng63 ~]# docker login
- Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
- Username: mufenggrow
- Password:
- 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@mufeng63 ~]#
复制代码
道勤主机提供365天*24小时全年全天无休、实时在线、零等待的售后技术支持。竭力为您免费处理您在使用道勤主机过程中所遇到的一切问题!
如果您是道勤主机用户,那么您可以通过QQ【792472177】、售后QQ【59133755】、旺旺【诠释意念】、微信:q792472177免费电话、后台提交工单这些方式联系道勤主机客服!
如果您不是我们的客户也没问题,点击页面最右边的企业QQ在线咨询图标联系我们并购买后,我们为您免费进行无缝搬家服务,让您享受网站零访问延迟的迁移到道勤主机的服务! |