本章节会学习:

  • docker commit
  • docker build
  • Dockerfile 文件

Step 1: 创建 Docker Hub账户

Step 2: Docker login

$ docker login

【Docker】Docker入门系列_3.2 使用 docker commit 构建镜像

Step 3: 构建镜像有两种方式,通过commit, 和通过dockerfile,

commit 仅仅能够把即时的状态保存下来,但无法知道经过哪些操作达到那个状态。

dockerfile 的工作方式是,从创建好底层镜像后,每一步需要执行的 shell 命令都写在 dockerfile内。

完全的透明性,以及可重复性。即使哪一步有问题也是一目了然。

使用commit 构建镜像:

$ docker run -i -t centos /bin/bash

$ yum install update 

$ yum install httpd

$ exit

$ docker commit <container ID> shengda/apache             

在一个centos 容器安装好 apache 后退出,运行 docker commit ,上传该容器到   < docker hub account> / <repo name>

最后是docker账户以及docker hub 仓库的名称。

$ docker image shengda/apache

可以查看上传的镜像

$ docker commit -m="A new custom image" --author="Shengda" \

<container ID> shengda / apache: webserver 

这里使用 -m 参数提交description 描述信息,--author 作者信息,最后给镜像添加 TAG : webserver

【Docker】Docker入门系列_3.2 使用 docker commit 构建镜像

$ docker inspect shengda / apache:webserver

【Docker】Docker入门系列_3.2 使用 docker commit 构建镜像

 

 

相关文章:

  • 2021-04-26
  • 2021-07-16
  • 2021-11-28
  • 2021-11-24
  • 2021-12-02
  • 2022-02-27
  • 2022-01-13
猜你喜欢
  • 2021-10-16
  • 2021-04-06
  • 2022-01-13
  • 2022-12-23
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案