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 ...
随机推荐
- js操作对象属性用点和用中括号有什么不同
书读百遍其义自见 学习<JavaScript设计模式>一书时,学习工厂模式这一章节,发现了对象后使用中括号的情况,如下: var Factory=function(type,content ...
- JavaScript深入之变量对象(转载)
前言 在上篇<JavaScript深入之执行上下文栈>中讲到,当 JavaScript 代码执行一段可执行代码(executable code)时,会创建对应的执行上下文(executio ...
- OC学习--OC中的类--类的定义,成员变量,方法
1. 类的定义 >用关键字@interface进行声名 @end 结束 >所有的类有一个基类NSobject >类名 也是标示符 第一个字母大写 如果多个字母组成 每个单词的首字母 ...
- Beta-星期五
所属课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass 作业要求 https://edu.cnblogs.com/camp ...
- python常用魔法函数
1.__init__(): 所有类的超类object,有一个默认包含pass的__init__()实现,这个函数会在对象初始化的时候调用,我们可以选择实现,也可以选择不实现,一般建议是实现的,不实现对 ...
- Mac brew 安装Postgres 开机自启动
以下所有命令在mac 终端执行 1.安装postgres brew install postgres 2.brew 安装的程序都可以在/usr/local/Cellar/下找到,去/usr/local ...
- phpstorm git配置
一. 安装git apt-get install git 二. 选择file->setting->Version Control->git 在此输入框输入git的执行路径 三.配置g ...
- k8s-calico【转载】
环境 系统:centos7.3192.168.40.50 local-master192.168.40.51 local-node1192.168.40.52 local-node2 master: ...
- 《DNS稳定保障系列3--快如闪电,域名解析秒级生效》
在刚刚过去的双十一,又是一个全民狂欢的盛宴,天猫双十一的成交量高达2684亿.无数小伙伴在淘宝.天猫里买买买,今年你又剁手了多少?言归正传,在你疯狂秒杀的时候,有没有发现,今年的购物体验一如既往的好, ...
- APP开发者如何从应用程序中赚钱?
付费应用程序,这是应用程序最基本的赚钱方式之一,也是拥有巨大潜力的赚钱方式之一.但有一个问题开发者必须扪心自问,您的程序用户是否有一批粉丝级用户的认可,或对您应用程序品牌的认可 蝉大师APP推广工 ...