制作docker镜像-容器

  • Dockerfile
  • 基于容器
  • docker hub automated build(依据dockerfile制作)

在这里插入图片描述

基于容器制作镜像,我们会先安装一个基础镜像,然后在基础镜像的基础上安装别的应用或者配置,完成后执行docker commit 命令提交到docker hub.

Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
在这里插入图片描述

以我之前机器上安装的busybox为例:

step1
docker container run --name busybox1 -it busybox
step2

在根目录下创建/data/page/index.html

mkdir -p /data/page/
vi index.html

在文件中输入hello world

setp3

保持docker container启动的状态下,执行命令:

docker commit -p busybox1

因为这个命令里我们没有加tag和repository,所以生成的镜像如下:
在这里插入图片描述
我们可以在后期去修改一个文件的tag和repository

docker tag 22e17e3bd56f levi/busybox_httpd:v0.1

在这里插入图片描述

step4

根据新制作的镜像,启动容器:

docker run --name busybox-levi -it levi/busybox_httpd:v0.1

使用inspect命令查看容器的启动命令如下:

docker inspect busybox-levi

在这里插入图片描述
创建一个新的镜像,并且修改启动参数:

docker commit -a "levi<leveldc@126.com>" -c 'CMD ["/bin/httpd","-f", "-h", "/data/page"]' -p  busybox-levi levi/busybox_httpd:v0.2
docker image ls

在这里插入图片描述

 docker run --name busybox-0.2 levi/busybox_httpd:v0.2

在另外一个终端中查看busybox-0.2的地址,并执行curl命令:
在这里插入图片描述

step5

推送镜像到hub.docker, 因为我的镜像的repository和tag都是随便取得,为了能推上去,我需要重新命名我的 repository 和 tag

docker tag levi/busybox_httpd:v0.2 leveldc/busybox_httpd:v0.1
--登陆dockerhub
docker push leveldc/busybox_httpd:v0.1

推送成功
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值