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. C#定时器,定时做什么事情

    http://www.cnblogs.com/bobositlife/archive/2015/09/29/aspnet-mvc-csharp-quartz-net-timer-task-schedu ...

  2. 【Two Sum】cpp

    题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...

  3. MFC深入浅出读书笔记第一部分

    最近看侯捷的MFC深入浅出,简单总结一下. 第一章首先就是先了解一下windows程序设计的基础知识,包括win32程序开发基础,什么*.lib,*.h,*.cpp的,程序入口点WinMain函数,窗 ...

  4. c4d 帮助 prime r16 usage

    c4d   帮助 prime cinema 4d   prime    c4d  基础 前言   usage 开始 双击程序图标   双击一个场景文件   用开始菜单  windows 二选一   从 ...

  5. hnust Snowman

    问题 D: Snowman 时间限制: 1 Sec  内存限制: 128 MB提交: 203  解决: 94[提交][状态][讨论版] 题目描述 前言:这是某比赛的热身题,本题主要考察英文水平,只要看 ...

  6. Html语言的标签讲解

    一.head头部中的内容: 1.<meta charset="UTF-8"> <--!告诉浏览器什么编码--> 2.<meta http-equiv= ...

  7. [HTTPS]pfx转jks

    keytool -importkeystore -srckeystore  src.pfx -srcstoretype pkcs12 -destkeystore trg.jks -deststoret ...

  8. Android版本对应的API号

    Android版本 API 级别 1.5 API 3 1.6 API 4 2.1 API 7 2.2 API 8 2.3.3 API 10 3.0 API 11 3.1 API 12 3.2 API ...

  9. linux开机关机自启动或自关闭服务的方式

    背景 由于迁移部门jira和confluence到linux,需要设置这两个服务在开机或关机时能够自动启动或关闭.这里我就拿配置confluence过程来记录. 方式1:chkconfig 特点:ch ...

  10. selenium webdriver——鼠标事件

    Web产品中提供了丰富的鼠标交互方式,例如鼠标右击.双击.悬停.甚至是鼠标拖动等功能,在WebDriver中,将这些关于鼠标操作的方法 封装在ActionChains类中: ActionChains类 ...