Docker生成镜像的两种方式

本文介绍了如何基于现有镜像构建自定义Docker镜像的两种方式:通过`docker commit`更新镜像和利用`docker build`结合Dockerfile创建新镜像。Dockerfile提供了自动化构建镜像的途径,包括指定基础镜像、复制文件、暴露端口等。通过`docker build`命令,用户可以根据Dockerfile构建自己的镜像,例如构建SpringBoot应用镜像。
摘要由CSDN通过智能技术生成

有时候从Docker镜像仓库中下载的镜像不能满足要求,我们可以基于一个基础镜像构建一个自己的镜像
两种方式:
1.更新镜像:使用docker commit命令
2.构建镜像:使用docker build命令,需要创建Dockerfile文件
更新镜像
先使用基础镜像创建一个容器,然后对容器内容进行更改,然后使用docker commit命令提交为一个新的镜像(以tomcat为例)。
1.根据基础镜像,创建容器

docker run --name mytomcat -p 80:8080 -d tomcat
  1. 修改容器内容
docker exec -it mytomcat /bin/bash
cd webapps/ROOT
rm -f index.jsp
echo hello world > index.html
exit

3.提交为新镜像
docker commit -m=“描述消息” -a="作者"容器ID或容器名
镜像名:TAG# 例:

# docker commit -m=“修改了首页” -a=“华安” mytomcat huaan/tomcat:v1.0

4.使用新镜像运行容器

docker run --name tom -p 8080:8080 -d
huaan/tomcat:v1.0

使用Dockerfile构建镜像
什么是Dockerfile?
Dockerfile is nothing but the source code for building Docker images
1.Docker can build images automatically by reading the instructions from a Dockerfile
2.A Dockerfile is a text document that contains

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值