docker--build自己的image
通过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的更多相关文章
- 【云计算】docker build如何支持参数化构建?
docker 1.9.0版本之后,已经支持docker build参数化构建. docker 版本更新记录: github讨论: 参开资料: https://github.com/docker/doc ...
- docker: "build" requires 1 argument. See 'docker build --help'.
http://bbs.csdn.net/topics/391040030 docker build --tag="ouruser/sinatra:v3" -<Dockerf ...
- Docker build Dockerfile 构建镜像 - 二
Dockerfile 制作镜像 https://hub.docker.com/ 搜索需要镜像: https://hub.docker.com/_/centos/ 官方示例: centos:6 1.这里 ...
- 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服务器上使用命 ...
- 25.week4 docker build 也就是创建自己的image 上传image到dockerhub 从dockerhub下载images
dado可以写你自己的名字 这个命令就会根据目录下的Dockerfile(固定用和这个名字)文件里面的内容 去下载并创建运行命令一步一步地 Setting up libxfixes3:amd64 (: ...
- docker build 指定dockerfile
1. Dockerfile文件使用 docker build命令会根据Dockerfile文件及上下文构建新Docker镜像.构建上下文是指Dockerfile所在的本地路径或一个URL(Git仓库地 ...
- "docker build" requires exactly 1 argument(s).
Docker 是怎么样的东西,这里就不说了,这里说说dockerfile创建容器时遇到的问题. 首先我想达到的目的很简单,就是用dockerfile去创建容器,步骤如下: 创建并编辑dockerfil ...
- 使用dockerfile文件创建镜像时docker build没有反应
问题: 先 docker pull centos:7 拉取了一个官方的基础镜像,为后续创建jdk8镜像做准备,在创建如下的dockerfile文件 执行docker build -t jdk_8u19 ...
- gradle multiproject && docker build
备注: 环境准备 : docker , gradle(使用wrapper,或者全局安装),测试环境使用mac 1. gradle 安装 brew install gradle 2. docke ...
- docker build
nginx Docfile ----------------------- FROM centos MAINTAINER daniel RUN yum install -y wget RUN ...
随机推荐
- tornado ioloop current和instance的一些区别
import tornado.ioloop # 此时_current没有instance print dir(tornado.ioloop.IOLoop._current) # 通过instance ...
- Java Predicate
Predicate 接口说明 /* * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * O ...
- rpm - RPM 软件包管理器
SYNOPSIS 查询和校验软件包: rpm {-q|--query} [select-options] [query-options] rpm {-V|--verify} [select-optio ...
- repquota - 文件系统配额的汇总
SYNOPSIS(总览) repquota [ -vugs ] filesystem... repquota [ -avugs ] DESCRIPTION(描述) repquota 显示与配额文件相关 ...
- 13-H.264编码解码器的无线应用:1080P60 3D无线影音传输器
H.264编码解码器的无线应用:1080P60 3D无线影音传输器 一.应用领域 家庭媒体娱乐中心 新闻现场采访 无线3D投影机 高清视频会议终端无线延长器 教学,医疗示教 考古,高档商业区域,监狱等 ...
- numpy知识点总结
一.数组方法 创建数组:arange()创建一维数组:array()创建一维或多维数组,其参数是类似于数组的对象,如列表等 反过来转换则可以使用numpy.ndarray.tolist()函数,如a. ...
- Minor GC与Full GC分别在什么时候发生?
Minor GC 当Eden区没有足够空间进行分配时,虚拟机就会进行一次Minor GC 新生代的垃圾收集动作,采用的是复制算法 对于较大的对象,在Minor GC的时候可以直接进入老年代 Full ...
- springboot打包成jar文件无法正常运行,解决办法已经找到
1.用intellij idea 创建了一个springboot的项目,前期都运行的好好的,在ide中可以正常运行,但是打包成Jar运行却一直报错. 2.经过不懈探索,终于找到解决办法 3.首先,找到 ...
- 第四章 走进jVM
4.1字节码 java文件编译成字节码后由默认解释执行,热点代码编译执行.方法调用到一定程度的时候,进行JIT编译成机器码执行,后面直接运行JIT编译结果(机器码). 4.2类加载过程 加载链接初始化 ...
- python爬虫:2.每天爬取数据量是多少?
带宽 网站阈值 单机 分布式 几百万