docker 系列5 创建镜像

一创建镜像

  创建镜像的方法主要有三种:基于已有镜像的容器创建、基于本地模板导入 、基于dockerfile创建,本节主要介绍docker的commit, import,build子命令

  1.基于已有容器创建

   该方法主要是使用docker [container] commit命令。 命令格式为docker [container] commit [options] container [repository[:TAG]]主要选项包括:

    -a, --author=""  作者信息

    -c, --change=[] 提交的时候执行dockerfile指令,包括cmd |entrypoint |env |expose |lable |onbuild |user |volume |workdir等;

    -m,  -message="" 提交消息

    -p, --pause=true 提交时暂停容器运行

   文档:https://docs.docker.com/engine/reference/commandline/commit/

  下面演示如何使用该命令创建一个新镜像

[root@VM_0_12_centos ~]# docker run -it hello-world  /bin/bash
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
Digest: sha256:8e3114318a995a1ee497790535e7b88365222a21771ae7e53687ad76563e8e76
Status: Downloaded newer image for hello-world:latest
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown.
[root@VM_0_12_centos ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                         PORTS               NAMES
b01d0e51debf        hello-world         "/bin/bash"         23 seconds ago      Created                                            peaceful_turing
e709d22a467d        hello-world         "/hello"            About an hour ago   Exited (0) About an hour ago                       distracted_lalande
6a8fc2b94a89        hello-world         "/hello"            4 hours ago         Exited (0) 4 hours ago                             naughty_chatelet

   未完成...

  2. 基于本地模板导入

   未完成...

 

  3. dockerfile创建

  重点要了解基于dockerfile创建,这是一种最常见的方式,dockerfile是一个文本文件,利用给定的指令描述基于某个父镜像创建新镜像的过程,下面给出一个dockerfile的简单示例:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
WORKDIR /app
EXPOSE 30001
COPY . .
ENTRYPOINT ["dotnet", "k8swebapi.dll"]

   基于mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime来安装asp.net core运行环境,创建镜像的过程可以使用docker [image] build命令(该web目录下build),编译成功后本地将多出一个k8swebapi镜像。

二.存出和载入镜像

  本节主要介绍docker镜像的save和load子命令,用户可以使用docker [image] save和docker [image] load命令来存出和载入镜像

   

 

  

posted on 2022-12-19 17:14  花阴偷移  阅读(4)  评论(0编辑  收藏  举报

导航