通过container commit成image

[root@localhost docker_test]# docker container commit #可以简写成docker commit
"docker container commit" requires at least and at most arguments.
See 'docker container commit --help'. Usage: docker container commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] Create a new image from a container's changes
[root@localhost docker_test]# docker image build #可以简写成docker build
"docker image build" requires exactly argument.
See 'docker image build --help'. Usage: docker image build [OPTIONS] PATH | URL | - Build an image from a Dockerfile

以centos image为例,centos base image 默认没安装vim,进入交互式,yum install vim

[root@localhost docker_test]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
bigni/test1 latest f5620b92331c hours ago 861kB
ubuntu 14.04 2c5e00d77a67 weeks ago 188MB
centos latest 9f38484d220f months ago 202MB
hello-world latest fce289e99eb9 months ago .84kB
[root@localhost docker_test]# docker run centos
[root@localhost docker_test]# docker run centos -it
docker: Error response from daemon: OCI runtime create failed: container_linux.go:: starting container process caused "exec: \"-it\": executable file not found in $PATH": unknown.
ERRO[] error waiting for container: context canceled
[root@localhost docker_test]# docker run -it centos
[root@dba873e57276 /]# ls
anaconda-post.log bin dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@dba873e57276 /]# vim
bash: vim: command not found
[root@dba873e57276 /]# yum install -y vim
[root@localhost docker_test]# docker container ls -a #查看所有container
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dba873e57276 centos "/bin/bash" minutes ago Exited () seconds ago infallible_rubin
36c7c2011bdb centos "-it" minutes ago Created wonderful_haslett
2401371f2c7a centos "/bin/bash" minutes ago Exited () minutes ago vibrant_dijkstra
[root@localhost docker_test]# docker commit
"docker commit" requires at least and at most arguments.
See 'docker commit --help'. Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] #docker commit 使用方法 Create a new image from a container's changes
[root@localhost docker_test]# docker commit infallible_rubin bigni/centos_vim #把names:infallible_rubin 的container commit 成image:bigni/centos_vim
sha256:afe852c481e754b88b28a663f6e98e0a52816e253c64af4b2b823f8bb8702961
[root@localhost docker_test]# docker image ls -a #查看新增image,比centos image大了好多,安装vim 需要的依赖包不少。
REPOSITORY TAG IMAGE ID CREATED SIZE
bigni/centos_vim latest afe852c481e7 seconds ago 362MB
<none> <none> 3ec8199c2855 hours ago 861kB
bigni/test1 latest f5620b92331c hours ago 861kB
ubuntu 14.04 2c5e00d77a67 weeks ago 188MB
centos latest 9f38484d220f months ago 202MB
hello-world latest fce289e99eb9 months ago .84kB
[root@localhost docker_test]# docker run -it bigni/centos_vim #交互式运行
bigni/centos_vim bigni/centos_vim:latest
[root@localhost docker_test]# docker run -it bigni/centos_vim #交互式运行,测试能不能使用vim
[root@3afa6597d516 /]# vim test
[root@3afa6597d516 /]# cat test
docker so easy
[root@3afa6597d516 /]# exit #退出
exit
[root@localhost docker_test]# docker container ls -a #可以看到新增一个container
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3afa6597d516 bigni/centos_vim "/bin/bash" About a minute ago Exited () seconds ago cranky_zhukovsky
dba873e57276 centos "/bin/bash" minutes ago Exited () minutes ago infallible_rubin
36c7c2011bdb centos "-it" minutes ago Created wonderful_haslett
2401371f2c7a centos "/bin/bash" minutes ago Exited () minutes ago vibrant_dijkstra
[root@localhost docker_test]#

查看原始的centos image 和新增的image

[root@localhost docker_test]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
bigni/centos_vim latest afe852c481e7 minutes ago 362MB
bigni/test1 latest f5620b92331c hours ago 861kB
ubuntu 14.04 2c5e00d77a67 weeks ago 188MB
centos latest 9f38484d220f months ago 202MB
hello-world latest fce289e99eb9 months ago .84kB
[root@localhost docker_test]# docker history 9f38484d220f
IMAGE CREATED CREATED BY SIZE COMMENT
9f38484d220f months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> months ago /bin/sh -c #(nop) LABEL org.label-schema.sc… 0B
<missing> months ago /bin/sh -c #(nop) ADD file:074f2c974463ab38c… 202MB
[root@localhost docker_test]# docker history afe852c481e7
IMAGE CREATED CREATED BY SIZE COMMENT
afe852c481e7 minutes ago /bin/bash 160MB #可以看到,比原始的image多了一层 layer
9f38484d220f months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> months ago /bin/sh -c #(nop) LABEL org.label-schema.sc… 0B
<missing> months ago /bin/sh -c #(nop) ADD file:074f2c974463ab38c… 202MB
[root@localhost docker_test]#

上面就是通过docker commit 在base image至少build自己的image,这种方式不值得提倡,因为当把这个image发布出去后,别人并不知该image安装了什么,

而且也有可能是不安全的image。

另一种方式是通过Dockerfile来build一个image。

[root@localhost ~]# mkdir docker_vim
[root@localhost ~]# vim docker_vim/Dockerfile
[root@localhost ~]# cat docker_vim/Dockerfile
FROM centos
RUN yum install -y vim
[root@localhost ~]# docker build -t bigni/centos_vim ./docker_vim/ #通过dockerfile build 新的image
Sending build context to Docker daemon .048kB
Step / : FROM centos #from centos
---> 9f38484d220f #直接引用centos image这一层,而不会新创建一层
Step / : RUN yum install -y vim #运行Dockerfile里配置的命令
---> Running in 551ad2fd3374 #创建临时container
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package vim-enhanced.x86_64 :7.4.-.el7_6 will be installed
--> Processing Dependency: vim-common = :7.4.-.el7_6 for package: :vim-enhanced-7.4.-.el7_6.x86_64
中间省略---> Package perl-Pod-Usage.noarch :1.63-.el7 will be installed
--> Processing Dependency: perl(Pod::Text) >= 3.15 for package: perl-Pod-Usage-1.63-.el7.noarch
--> Finished Dependency Resolution Dependencies Resolved ================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
vim-enhanced x86_64 :7.4.-.el7_6 updates 1.0 M
Installing for dependencies:
中间省略which x86_64 2.20-.el7 base k Transaction Summary
================================================================================
Install Package (+ Dependent packages) Total download size: M
Installed size: M
Downloading packages:
warning: /var/cache/yum/x86_64//base/packages/gpm-libs-1.20.-.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for gpm-libs-1.20.-.el7.x86_64.rpm is not installed
Public key for perl-Pod-Escapes-1.04-.el7_6.noarch.rpm is not installed
--------------------------------------------------------------------------------
Total kB/s | MB :
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release--6.1810..el7.centos.x86_64 (@CentOS)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : gpm-libs-1.20.-.el7.x86_64 / 中间省略 Complete!
Removing intermediate container 551ad2fd3374
---> f853f2a3f901
Successfully built f853f2a3f901 #创建完成

查看创建的image

[root@localhost ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
bigni/centos_vim latest f853f2a3f901 minutes ago 362MB
bigni/test1 latest f5620b92331c hours ago 861kB
ubuntu 14.04 2c5e00d77a67 weeks ago 188MB
centos latest 9f38484d220f months ago 202MB

docker--build自己的image的更多相关文章

  1. 【云计算】docker build如何支持参数化构建?

    docker 1.9.0版本之后,已经支持docker build参数化构建. docker 版本更新记录: github讨论: 参开资料: https://github.com/docker/doc ...

  2. docker: "build" requires 1 argument. See 'docker build --help'.

    http://bbs.csdn.net/topics/391040030 docker build  --tag="ouruser/sinatra:v3" -<Dockerf ...

  3. Docker build Dockerfile 构建镜像 - 二

    Dockerfile 制作镜像 https://hub.docker.com/ 搜索需要镜像: https://hub.docker.com/_/centos/ 官方示例: centos:6 1.这里 ...

  4. Jenkins Docker安装及Docker build step插件部署配置

    生产部署环境:A:192.168.1.2 B:192.168.1.3  两台服务器系统均是Centos 7.3 , Docker版本都1.12.6 Jenkins安装操作步骤: 1.在A服务器上使用命 ...

  5. 25.week4 docker build 也就是创建自己的image 上传image到dockerhub 从dockerhub下载images

    dado可以写你自己的名字 这个命令就会根据目录下的Dockerfile(固定用和这个名字)文件里面的内容 去下载并创建运行命令一步一步地 Setting up libxfixes3:amd64 (: ...

  6. docker build 指定dockerfile

    1. Dockerfile文件使用 docker build命令会根据Dockerfile文件及上下文构建新Docker镜像.构建上下文是指Dockerfile所在的本地路径或一个URL(Git仓库地 ...

  7. "docker build" requires exactly 1 argument(s).

    Docker 是怎么样的东西,这里就不说了,这里说说dockerfile创建容器时遇到的问题. 首先我想达到的目的很简单,就是用dockerfile去创建容器,步骤如下: 创建并编辑dockerfil ...

  8. 使用dockerfile文件创建镜像时docker build没有反应

    问题: 先 docker pull centos:7 拉取了一个官方的基础镜像,为后续创建jdk8镜像做准备,在创建如下的dockerfile文件 执行docker build -t jdk_8u19 ...

  9. gradle multiproject && docker build

    备注:   环境准备 : docker , gradle(使用wrapper,或者全局安装),测试环境使用mac 1. gradle 安装 brew install gradle   2. docke ...

  10. docker build

    nginx Docfile ----------------------- FROM centos   MAINTAINER daniel   RUN yum install -y wget RUN ...

随机推荐

  1. 前端对base64编码的理解,原生js实现字符base64编码

    目录 常见对base64的认知(不完全正确) 多问一个为什么,base64到底是个啥? 按照我们的思路实现一下 到这里基本就实现了,结果跟原生的方法打印的是一样的 下一次 @( 对于前端工程师来说ba ...

  2. 数组Array的方法调用

    <script language="JavaScript" type="text/javascript"> var arr = ["11& ...

  3. weblogicjsp编译:查看编译后的java中间代码

    转自:https://www.xuebuyuan.com/1069484.html 运行自己配置的web应用,往往只能看见weblogic编译之后的class文件.而看不见编译前的java的文件.为了 ...

  4. 免费资源(CDN,顶级域名)汇集

    CloudFlare:免费CDN,需要将域名指向到cloudflare服务器.付费的可以使用二级域名 https://www.cloudflare.com/ Freenom:freenom会提供免费提 ...

  5. HTML基础 用div布局实现一个简单网页

    div布局如下 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <t ...

  6. mongodb 索引分类

    一. 普通索引篇 1.创建索引 创建索引:db.person.ensureIndex({"age":1}).这里我们使用了ensureIndex在age上建立了索引.“1”:表示按 ...

  7. 剑指Offer-51.构建乘积数组(C++/Java)

    题目: 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1].不能 ...

  8. boost number handling

    Boost.Integer defines specialized for integers. 1. types for integers with number of bits #include & ...

  9. boost graph

    Boost Graph provides tools to work with graphs. Graphas are two-dimensional point clouds with any nu ...

  10. python使用HTMLTestRunner.py生成测试报告

    这里我使用的是python selenium webdriver环境,浏览器驱动安装见selenium 1.下载HTMLTestRunner.py:http://tungwaiyip.info/sof ...