使用 docker 创建自己的镜像
docker run 命令
创建自己的镜像 image
- 创建一个 Dockerfile 文件
RUN apt-get -y update && apt-get install -y fortunes(whalesay 镜像是基于ubuntu的,使用apt-get install来安装packages. 这两个命令更新了packages包,并安装了fortune 程序)
CMD /usr/games/fortune -a | cowsay(告诉镜像image在环境设置好以后的最后一个命令,该命令运行了furtune -a,并将输出发给额cowsay命令)
- 根据 Dockerfile 来 Build 镜像
$ docker build -t docker-whale .Sending build context to Docker daemon 2.048 kB ...snip...Removing intermediate container cb53c9d09f3bSuccessfully built c2c3152907b5Docker检查确认所有build所需都齐了,输出如下消息:
Sending build context to Docker daemon 2.048 kB
Docker 检查
whalesayimage 是否存在,不存在则从Docker Hub上pull下来。Step 1 : FROM docker/whalesay:latest
---> 6b362a9f73eb
在每一步结束,都会有一个ID被打印出来。这个ID是每一步创建出的 Layer 的ID。 Dockerfile 中每一行命令都和 image 中的一个 Layer 相关。你自己的ID会显示的不一样。
Docker 创建一个临时容器 container 来运行
whalesay镜像image。在这个临时容器中,Docker 运行 Dockerfile中的下一条命令, 即RUN命令。这会安装fortune。这里会有很多输出,就和在 Ubuntu 中创建出来的消息一样。Step 2 : RUN apt-get -y update && apt-get install -y fortunes
---> Running in 05d4eda04526
Ign http://archive.ubuntu.com trusty InRelease
Get:1 http://archive.ubuntu.com trusty-updates InRelease [65.9 kB]
Get:2 http://archive.ubuntu.com trusty-security InRelease [65.9 kB]
Hit http://archive.ubuntu.com trusty Release.gpg
Hit http://archive.ubuntu.com trusty Release
Get:3 http://archive.ubuntu.com trusty-updates/main Sources [480 kB]
Get:4 http://archive.ubuntu.com trusty-updates/restricted Sources [5921 B]
Get:5 http://archive.ubuntu.com trusty-updates/universe Sources [214 kB]
Get:6 http://archive.ubuntu.com trusty-updates/main amd64 Packages [1160 kB]
Get:7 http://archive.ubuntu.com trusty-updates/restricted amd64 Packages [20.4 kB]
Get:8 http://archive.ubuntu.com trusty-updates/universe amd64 Packages [505 kB]
Get:9 http://archive.ubuntu.com trusty-security/main Sources [157 kB]
Get:10 http://archive.ubuntu.com trusty-security/restricted Sources [4621 B]
Get:11 http://archive.ubuntu.com trusty-security/universe Sources [54.5 kB]
Get:12 http://archive.ubuntu.com trusty-security/main amd64 Packages [700 kB]
Get:13 http://archive.ubuntu.com trusty-security/restricted amd64 Packages [17.0 kB]
Get:14 http://archive.ubuntu.com trusty-security/universe amd64 Packages [191 kB]
Hit http://archive.ubuntu.com trusty/main Sources
Hit http://archive.ubuntu.com trusty/restricted Sources
Hit http://archive.ubuntu.com trusty/universe Sources
Hit http://archive.ubuntu.com trusty/main amd64 Packages
Hit http://archive.ubuntu.com trusty/restricted amd64 Packages
Hit http://archive.ubuntu.com trusty/universe amd64 Packages
Fetched 3640 kB in 11s (329 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
fortune-mod fortunes-min librecode0
Suggested packages:
x11-utils bsdmainutils
The following NEW packages will be installed:
fortune-mod fortunes fortunes-min librecode0
0 upgraded, 4 newly installed, 0 to remove and 92 not upgraded.
Need to get 1961 kB of archives.
After this operation, 4817 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main librecode0 amd64 3.6-21 [771 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty/universe fortune-mod amd64 1:1.99.1-7 [39.5 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ trusty/universe fortunes-min all 1:1.99.1-7 [61.8 kB]
Get:4 http://archive.ubuntu.com/ubuntu/ trusty/universe fortunes all 1:1.99.1-7 [1089 kB]
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin:
Fetched 1961 kB in 19s (101 kB/s)
Selecting previously unselected package librecode0:amd64.
(Reading database ... 13116 files and directories currently installed.)
Preparing to unpack .../librecode0_3.6-21_amd64.deb ...
Unpacking librecode0:amd64 (3.6-21) ...
Selecting previously unselected package fortune-mod.
Preparing to unpack .../fortune-mod_1%3a1.99.1-7_amd64.deb ...
Unpacking fortune-mod (1:1.99.1-7) ...
Selecting previously unselected package fortunes-min.
Preparing to unpack .../fortunes-min_1%3a1.99.1-7_all.deb ...
Unpacking fortunes-min (1:1.99.1-7) ...
Selecting previously unselected package fortunes.
Preparing to unpack .../fortunes_1%3a1.99.1-7_all.deb ...
Unpacking fortunes (1:1.99.1-7) ...
Setting up librecode0:amd64 (3.6-21) ...
Setting up fortune-mod (1:1.99.1-7) ...
Setting up fortunes-min (1:1.99.1-7) ...
Setting up fortunes (1:1.99.1-7) ...
Processing triggers for libc-bin (2.19-0ubuntu6.6) ...
---> dfaf993d4a2e
Removing intermediate container 05d4eda04526
RUN结束,有一个 layer 会被创建,并且之前创建的临时容器 container 也被去除了。一个新的临时容器 container 被创建出来,Docker 为CMD命令添加一个 Layer,然后在移除该容器 congtainer
Step 3 : CMD /usr/games/fortune -a | cowsay
---> Running in a8e6faa88df3
---> 7d9495d03763
Removing intermediate container a8e6faa88df3
Successfully built 7d9495d03763
到这里,我们就创建了一个自己的镜像 image,名叫 docker-whale.
接下来直接运行 docker run docker-whale
使用 docker 创建自己的镜像的更多相关文章
- docker创建自己的镜像并配置nginx
前言 最近在研究docker,记录一下如何创建一个属于自己的镜像 本次使用linux版本为centos7.4(centos6也可以使用docker,只不过有部分功能只有7才有) 本次创建的镜像为cen ...
- docker 创建新的镜像到私有仓库
docker:/data# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bd6db4127a9e centos &q ...
- Docker入门(windows版),利用Docker创建一个Hello World的web项目
Docker 当大家点开这篇博客的时候,相信大家对docker多多少少也有些认识了,最近学习docker这门技术,略微有些心得,写篇文章记录一下学习过程并帮大家跳过一些坑. docker的核心有两个, ...
- docker学习之二镜像创建
继上一篇docker入门之后写一点使用的经验. 通过命令:docker run -it REPOSITORY或IMAGE ID 注:-it后面跟的字段可以通过下面指令获得 创建运行的容器,会进入一 ...
- Docker 基于已有镜像的容器创建镜像
Docker 基于已有镜像的容器创建镜像: docker:/root# docker run -it januswel/centos /bin/bash docker exec -it januswe ...
- Docker创建支持ssh服务的容器和镜像
原文链接:Docker创建支持ssh服务的容器和镜像 1. 这里使用的centos作为容器,所以首先下载centos的images # sudo docker pull centos 2. 下载后执行 ...
- docker commit命令创建新的镜像
docker commit命令创建新的镜像 1.运行容器 2.修改容器 3.将容器保存为新容器 (1)运行容器 [root@cmdb-server docker]# docker run -ti ce ...
- docker学习系列(二):使用Dockerfile创建自己的镜像
dockerfile可以允许我们自己创建镜像,通过编写里面的下载软件命令,执行docker build 即可生成镜像文件. 初尝dockerfile 新建一个目录test,然后进入这个目录,创建一个名 ...
- docker创建redis镜像
pull redis 镜像 创建redis的镜像有几种方式,可以直接从仓库中拉取,也可以采用dockerfile文件自己编译创建. 基于已有的redis镜像,docker可以采用run,或者creat ...
随机推荐
- kettle学习笔记(五)——kettle输出步骤
一.概述 数据库表: • 表输出 • 更新,删除,插入/更新 • 批量加载(mysql,oracle) • 数据同步 文件: • SQL 文件输出 • 文本文件输出 • XML 输出 • Excel ...
- 2017-2018 Exp7 网络欺诈技术防范 20155214
目录 Exp7 网络欺诈技术防范 实验内容 信息收集 知识点 Exp7 网络欺诈技术防范 实验内容 实验环境 主机 Kali 靶机 Windows 10 实验工具 平台 Metaploit 信息收集 ...
- 云计算背后的秘密:NoSQL诞生的原因和优缺点
转载收藏一篇对nosql讲解的比较全面的文章:http://blog.csdn.net/xlgen157387/article/details/47908797 这篇文章将和大家聊聊为什么NoSQL会 ...
- Git配置用户名与邮箱
1.用户名和邮箱地址的作用 用户名和邮箱地址是本地git客户端的一个变量 每次commit都会用用户名和邮箱纪录. github的contributions统计就是按邮箱来统计的. 2.查看用户名和邮 ...
- MySql+Socket 完成数据库的增查Demo
需求: 利用MySql数据库结合前端技术完成用户的注册(要求不使用Web服务技术),所以 Demo采用Socket技术实现Web通信. 第一部分:数据库创建 数据库采用mysql 5.7.18, 数据 ...
- 关于Trie的一些算法
最近学习了一下关于Trie的一些姿势,感觉很实用. 终于不用每次看到字符串判重等操作就只想到hash了 关于Trie的定义,来自百度百科 在计算机科学中,Trie,又称前缀树或字典树,是一种有序树状的 ...
- Js_封装JQ库为插件
//在jQuery匿名函数中,采用jQuery.extend();方法创建jQuery插件 //在jQuery匿名函数中, 采用对象.属性 = 函数的方式创建jQuery插件 (function ($ ...
- CommandoVM-虚拟机映像文件 | VM打开直接用
呵呵!自从火眼发布了这个CommandoVM,想必大家应该都挺激动,然而实际操作一下,基本炸裂-- 因为并没有给类似于kali这种直接安装的现成镜像,而是要通过github的脚本去完全网络安装 实际操 ...
- 如何理解nexus
理解: Nexus即区块链:分布式部署肯定是构建去中心化网络理所当然的解决方向--通过P2P协议将全世界所有节点计算机彼此相互连接,形成一张密密麻麻的网络:以巧妙的机制,通过节点之间的交易数据同步来保 ...
- EOS开发基础之一:源代码下载与开发环境搭建
区块链最近挺火的,我又是个非常缺钱的人,所以紧跟了潮流一头扎进区块链的研究中. 这EOS项目是目前比较火的一个项目,相信很多朋友拿到这份EOS的源代码后都会一脸懵逼,因为……这代码写得太高级了,老纸看 ...