images 是containers的基础。每次使用docker run 命令都要指定image。
 
列出本地images

 
zane@zane-V:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zane0306/docker-whale latest d09756981eeb hours ago 275.1 MB
ubuntu latest 104bec311bcd days ago MB
hello-world latest c54a2cc56cbb months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb months ago MB
training/webapp latest 6fae60ef3446 months ago 348.8 MB
 
寻找获取新image

 
寻找一下centos images。
zane@zane-V:~$ docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. [OK]
jdeathe/centos-ssh CentOS- 6.8 x86_64 / CentOS- 7.3. x8... [OK]
nimmis/java-centos This is docker images of CentOS with dif... [OK]
torusware/speedus-centos Always updated official CentOS docker imag... [OK]
egyptianbman/docker-centos-nginx-php A simple and highly configurable docker co... [OK]
nathonfowlie/centos-jre Latest CentOS image with the JRE pre-insta... [OK]
centos/mariadb55-centos7 [OK]
 
docker pull 下载image
zane@zane-V:~$ docker pull centos
Using default tag: latest
latest: Pulling from library/centos 45a2e645736c: Pull complete
Digest: sha256:c577af3197aacedf79c5a204cd7f493c8e07ffbce7f88f7600bf19c688c38799
Status: Downloaded newer image for centos:latest
 
启动一个容器
zane@zane-V:~$ docker run  -t -i  centos /bin/bash
[root@a57fbae352e1 /]# ls
anaconda-post.log dev home lib64 media opt root sbin sys usr
bin etc lib lost+found mnt proc run srv tmp var
 
training/sinatra下载
zane@zane-V:~$  docker pull training/sinatra
Using default tag: latest
latest: Pulling from training/sinatra a3ed95caeb02: Pull complete
6e71c809542e: Pull complete
d196a7609355: Pull complete
08f6dff5acea: Pull complete
ce65532003d0: Pull complete
54bcaa4d1a10: Pull complete
8572ad96f6e1: Pull complete
Digest: sha256:03fc0cd265cbc28723e4efd446f9f2f37b4790cf9cc12f1b9203c79fb86b6772
Status: Downloaded newer image for training/sinatra:latest
创建自己的images

 
虽然training/sinatra ,image已经非常好了,但是可能我们要增加一些功能。
更新和创建images的两种方法
  • 更新容器,并提交更改结果到image
  • 使用Dockerfile 指定说明来创建一个image
 
更新和提交image
 
创建容器用来更新
zane@zane-V:~$ docker run -t -i training/sinatra /bin/bash
root@b9d598059fa9:/#
查看正在运行的容器
zane@zane-V:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b9d598059fa9 training/sinatra "/bin/bash" seconds ago Up seconds desperate_bose
在运行的容器中让我们先升级 Ruby
root@b9d598059fa9:/# apt-get install -y ruby2.-dev ruby2.
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
.......
.......
再来安装json
root@b9d598059fa9:/# gem2. install json
Fetching: json-2.0..gem (%)
Building native extensions. This could take a while...
Successfully installed json-2.0.
Parsing documentation for json-2.0.
unable to convert "\xD0" from ASCII-8BIT to UTF- for lib/json/ext/generator.so, skipping
unable to convert "\xD0" from ASCII-8BIT to UTF- for lib/json/ext/parser.so, skipping
Installing ri documentation for json-2.0.
gem installed
完成更新之后,退出容器使用exit 命令。
root@b9d598059fa9:/# exit
exit
zane@zane-V:~$
提交
docker commit命令提交
-m : 说明更改
-a  :  更改作者
 
b9d598059fa9:更改的容器ID
sinatra:v2       :提交到sinatra image ,v2是tag;
zane@zane-V:~$ docker commit -m "Added json gem" -a "zane" b9d598059fa9 sinatra:v2
sha256:7902e96eb0144d64577348c02ff8accf939e5469c01df9a0911044122205b8c7 zane@zane-V:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sinatra v2 7902e96eb014 About a minute ago 471.2 MB
zane0306/docker-whale latest d09756981eeb hours ago 275.1 MB
centos latest 67591570dd29 days ago 191.8 MB
ubuntu latest 104bec311bcd days ago MB
hello-world latest c54a2cc56cbb months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb months ago MB
training/webapp latest 6fae60ef3446 months ago 348.8 MB
training/sinatra latest 49d952a36c58 years ago MB
可以看到commit 之后,在本地出现了我们本地image
 
使用Dockerfile创建image
 
docker build 命令 读取Dockerfile 来创建image
 
创建目录以及Dockerfile
zane@zane-V:~$ mkdir sinatra
zane@zane-V:~$ cd sinatra/
zane@zane-V:~/sinatra$ touch Dockerfile
Dockerfile内容
# This is a comment
FROM ubuntu:14.04
MAINTAINER zane zane.zhang@zoom.us
RUN apt-get update && apt-get install -y ruby ruby-dev
RUN gem install sinatra
  • #: 注释
  • FROM
    • 以哪个image为基础
  • maintainer
    • 作者
  • RUN
    • 在基础image上做一些实质性操作
 
docker build 创建image
zane@zane-V:~/sinatra$ docker build -t zane/sinatra:v1 .
Sending build context to Docker daemon 2.048 kB
Step : FROM ubuntu:14.04
14.04: Pulling from library/ubuntu 16da43b30d89: Pulling fs layer
1840843dafed: Pulling fs layer
91246eb75b7d: Pulling fs layer
7faa681b41d7: Waiting
97b84c64d426: Waiting
-t 参数给image名称 zane/sinatra,以及标签 v1
不要忘记 . 命令,它告诉docker build 在本目录寻找调用Dockerfile。
 
zane@zane-V:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zane/sinatra v1 c0e79450b1a1 About a minute ago 322.4 MB
sinatra v2 7902e96eb014 minutes ago 471.2 MB
zane0306/docker-whale latest d09756981eeb hours ago 275.1 MB
centos latest 67591570dd29 days ago 191.8 MB
ubuntu latest 104bec311bcd days ago MB
ubuntu 14.04 3f755ca42730 days ago MB
hello-world latest c54a2cc56cbb months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb months ago MB
training/webapp latest 6fae60ef3446 months ago 348.8 MB
training/sinatra latest 49d952a36c58 years ago MB
 
设置image的标签

 
zane@zane-V:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sinatra v2 7902e96eb014 minutes ago 471.2 MB
zane0306/docker-whale latest d09756981eeb hours ago 275.1 MB
centos latest 67591570dd29 days ago 191.8 MB
ubuntu latest 104bec311bcd days ago MB
ubuntu 14.04 3f755ca42730 days ago MB
hello-world latest c54a2cc56cbb months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb months ago MB
training/webapp latest 6fae60ef3446 months ago 348.8 MB
training/sinatra latest 49d952a36c58 years ago MB
给sinatra增加一个tag vv
zane@zane-V:~$ docker tag 7902e96eb014 sinatra:vv

zane@zane-V:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE B
sinatra v2 7902e96eb014 minutes ago 471.2 MB
sinatra vv 7902e96eb014 minutes ago 471.2 MB
zane0306/docker-whale latest d09756981eeb hours ago 275.1 MB
centos latest 67591570dd29 days ago 191.8 MB
ubuntu latest 104bec311bcd days ago MB
ubuntu 14.04 3f755ca42730 days ago MB
hello-world latest c54a2cc56cbb months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb months ago MB
training/webapp latest 6fae60ef3446 months ago 348.8 MB
training/sinatra latest 49d952a36c58 years ago MB
当然也可以给指定不同的repository名称,以及tag名;
zane@zane-V:~$ docker tag 7902e96eb014 zane-sinatra:vv
zane@zane-V:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sinatra v2 7902e96eb014 minutes ago 471.2 MB
sinatra vv 7902e96eb014 minutes ago 471.2 MB
zane-sinatra vv 7902e96eb014 minutes ago 471.2 MB
zane0306/docker-whale latest d09756981eeb hours ago 275.1 MB
centos latest 67591570dd29 days ago 191.8 MB
ubuntu latest 104bec311bcd days ago MB
ubuntu 14.04 3f755ca42730 days ago MB
hello-world latest c54a2cc56cbb months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb months ago MB
training/webapp latest 6fae60ef3446 months ago 348.8 MB
training/sinatra latest 49d952a36c58 years ago MB
 
image摘要
$ docker images --digests | head REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE ouruser/sinatra latest sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf 5db5f8471261  hours ago 446.7 MB
 
可以用来指定要拉下来的是哪个版本
 
push image 到 Docker Hub
zane@zane-V:~$ docker push zane/sinatra
The push refers to a repository [docker.io/zane/sinatra]
e9170f93385d: Preparing
d375b10aba64: Preparing
4fcb79d431cc: Preparing
4375cecd293e: Preparing
738d3f35b582: Preparing
53edc9780c07: Waiting
bc224b1b676d: Waiting
unauthorized: authentication required
 
删除本地image
zane@zane-V:~$ docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Deleted: sha256:c54a2cc56cbb2f04003c1cd4507e118af7c0d340fe7e2720f70976c4b75237dc
Deleted: sha256:a02596fdd012f22b03af6ad7d11fa590c57507558357b079c3e8cebceb4262d7
 
总结

  1. 寻找获取新image

    • docker search centos
  2. 从docker hub 上pull下来
    • docker pull centos
  3. 启动一个容器
    • docker run  -t -i  centos /bin/bash
  4. 创建image两种方式
      • 更新容器,并提交更改结果到image

        • a.运行容器
        • b.安装新软件如:ruby,python,json
        • c.提交
          • docker commit -m "Added json gem" -a "zane" b9d598059fa9 sinatra:v2
          • -m :说明,-a:作者,
          • 将容器b9d598059fa9的更改提交到sinatra 镜像的V2标签
      • 使用Dockerfile,创建新image
        • 编写dockerfile
        • 运行build 命令
  5. 给image增加标签
    • docker tag 7902e96eb014 sinatra:vv

Docker 创建image的更多相关文章

  1. Docker创建支持ssh服务的容器和镜像

    原文链接:Docker创建支持ssh服务的容器和镜像 1. 这里使用的centos作为容器,所以首先下载centos的images # sudo docker pull centos 2. 下载后执行 ...

  2. Docker创建MySQL集装箱

    原文链接:Docker创建MySQL集装箱 这样做的目的是创建一个MySQL的image,出来的容器里自己主动启动MySQL服务接受外部连接 步骤: 1. 首先创建一个文件夹并在文件夹下创建一个Doc ...

  3. Docker 创建 Crucible4.6.1 以及与 Crowd3.3.2 实现 SSO 单点登录

    目录 目录 1.介绍 1.1.什么是 Crucible? 2.Crucible 的官网在哪里? 3.如何下载安装? 4.对 Crucible 进行配置 4.1.破解 Crucible 第一步 4.2. ...

  4. Docker 创建 Crowd3.3.2 以及打通 Jira Software7.12.3和Confluence6.12.2 SSO 单点登录

    目录 目录 1.介绍 1.1.什么是Crowd? 2.Crowd 的官网在哪里? 3.如何下载安装? 4.对 Crowd 进行配置 4.1.破解 Crowd 第一步 4.2.破解 Crowd 第二步, ...

  5. Docker 创建 Bamboo6.7.1 以及与 Crowd3.3.2 实现 SSO 单点登录

    目录 目录 1.介绍 1.1.什么是 Bamboo? 2.Bamboo 的官网在哪里? 3.如何下载安装? 4.对 Bamboo 进行配置 4.1.获取授权许可 4.2.一般配置 4.3.数据库配置 ...

  6. Docker 创建 Jira Core(Jira SoftWare) 7.12.3 中文版

    目录 目录 1.介绍 1.1.什么是 JIRA Core? 1.2.什么是 JIRA SoftWare 2.JIRA 的官网在哪里? 3.如何下载安装? 4.对 JIRA 进行配置 4.1.JIRA ...

  7. Docker 创建 Confluence6.12.2 中文版

    目录 目录 1.介绍 1.1.什么是Confluence? 2.Confluence的官网在哪里? 3.如何下载安装? 4.对 Confluence 进行配置 4.1.设置 Confluence 4. ...

  8. Docker创建JIRA 7.2.4中文破解版

    目录 目录 1.介绍 1.1.什么是JIRA? 2.JIRA的官网在哪里? 3.如何下载安装? 4.对JIRA进行配置 4.1.打开浏览器:http://localhost:20012 4.2.JIR ...

  9. Docker 创建容器 查看容器状态 - 三

    Docker 创建容器 1.拉取镜像 默认是 docker.io 仓最新镜像 docker pull tomcat 2.运行一个服务容器 docker run -d -p 0.0.0.0:18080: ...

  10. 使用 docker 创建自己的镜像

    docker run 命令 镜像(image):An image is a filesystem and parameters to use at runtime. It doesn't have s ...

随机推荐

  1. js中基础数据类型

    变量声明 undefined //未定义只声明   var age; alert(name);function fc(a1,a2,a3) { //alert(a1); //alert(a2); //a ...

  2. Careercup - Microsoft面试题 - 23123665

    2014-05-12 07:44 题目链接 原题: Given an array having unique integers, each lying within the range <x&l ...

  3. IOS开发---菜鸟学习之路--(三)-数据解析

    第三篇 上一篇我们讲了如何通过NSURL类来获取数据, 这一章我们来讲下对于获取过来的数据如何解析. 好了直接进入正文吧. 正文: 上一篇讲了 我们获取过来的数据格式是JSON格式的 大家可以搜下对应 ...

  4. 图说不为人知的IT传奇故事-5-小型机之王

    此系列文章为“图说不为人知的IT传奇故事”,各位大忙人可以在一分钟甚至几秒内了解把握整个内容,真可谓“大忙人的福利”呀!!希望各位IT界的朋友在钻研技术的同时,也能在文学.历史上有所把握.了解这些故事 ...

  5. Python+Selenium练习篇之11-浏览器上前进和后退操作

    本文来介绍上如何,利用webdriver中的方法来演示浏览器中地址栏旁边的前进和后退功能. 相关脚本代码如下: # coding=utf-8import timefrom selenium impor ...

  6. MySQL5.7(三)数据表操作

    概念在数据库中,数据表是数据库中最重要.最基本的操作对象,是数据存储的基本单位.数据表被定义为列的集合,数据在表中是按照行和列的格式来存储的.每一行代表一条唯一的记录,每一列代表记录中的一个域.1.创 ...

  7. python的重重之器(生成器、迭代器、装饰器)

    一.装饰器 1.定义:本质是函数,装饰其他函数就是为其他函数添加附件功能. 2.原则: a.不能修改被装饰的函数的源代码: b.不能修改被装饰的函数的调用方式: 实例: #!/usr/bin/env ...

  8. 系统中同时安装sql2005 和 sql2008 R2 提示要删除SQL Server 2005 Express

    修改注册表:HKLM\Software\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM,把 ShellSEM重命名即可 如果是64位机器 在  HKL ...

  9. nyoj 题目14 会场安排问题

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工 ...

  10. selenium webdriver——多表单切换与多窗口切换

    多表单切换 >>在Web应用中经常会遇到frame/iframe表单嵌套页面的应用,WebDriver只能在一个页面上对元素识别与定位,对于frame/iframe 表单内嵌页面上的元素无 ...