zane@zane-V:~$ docker run -t -i centos /bin/bash
[iyunv@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
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" 45 seconds ago Up 44 seconds desperate_bose
在运行的容器中让我们先升级 Ruby
root@b9d598059fa9:/# apt-get install -y ruby2.0-dev ruby2.0
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
.......
.......
再来安装json
root@b9d598059fa9:/# gem2.0 install json
Fetching: json-2.0.2.gem (100%)
Building native extensions. This could take a while...
Successfully installed json-2.0.2
Parsing documentation for json-2.0.2
unable to convert "\xD0" from ASCII-8BIT to UTF-8 for lib/json/ext/generator.so, skipping
unable to convert "\xD0" from ASCII-8BIT to UTF-8 for lib/json/ext/parser.so, skipping
Installing ri documentation for json-2.0.2
1 gem installed
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 30 hours ago 275.1 MB
centos latest 67591570dd29 11 days ago 191.8 MB
ubuntu latest 104bec311bcd 11 days ago 129 MB
hello-world latest c54a2cc56cbb 5 months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb 19 months ago 247 MB
training/webapp latest 6fae60ef3446 19 months ago 348.8 MB
training/sinatra latest 49d952a36c58 2 years ago 447 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 1 : FROM ubuntu:14.04
14.04: Pulling from library/ubuntu
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 21 minutes ago 471.2 MB
zane0306/docker-whale latest d09756981eeb 31 hours ago 275.1 MB
centos latest 67591570dd29 11 days ago 191.8 MB
ubuntu latest 104bec311bcd 11 days ago 129 MB
ubuntu 14.04 3f755ca42730 11 days ago 188 MB
hello-world latest c54a2cc56cbb 5 months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb 19 months ago 247 MB
training/webapp latest 6fae60ef3446 19 months ago 348.8 MB
training/sinatra latest 49d952a36c58 2 years ago 447 MB
设置image的标签
zane@zane-V:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sinatra v2 7902e96eb014 18 minutes ago 471.2 MB
zane0306/docker-whale latest d09756981eeb 31 hours ago 275.1 MB
centos latest 67591570dd29 11 days ago 191.8 MB
ubuntu latest 104bec311bcd 11 days ago 129 MB
ubuntu 14.04 3f755ca42730 11 days ago 188 MB
hello-world latest c54a2cc56cbb 5 months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb 19 months ago 247 MB
training/webapp latest 6fae60ef3446 19 months ago 348.8 MB
training/sinatra latest 49d952a36c58 2 years ago 447 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 19 minutes ago 471.2 MB
sinatra vv 7902e96eb014 19 minutes ago 471.2 MB
zane0306/docker-whale latest d09756981eeb 31 hours ago 275.1 MB
centos latest 67591570dd29 11 days ago 191.8 MB
ubuntu latest 104bec311bcd 11 days ago 129 MB
ubuntu 14.04 3f755ca42730 11 days ago 188 MB
hello-world latest c54a2cc56cbb 5 months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb 19 months ago 247 MB
training/webapp latest 6fae60ef3446 19 months ago 348.8 MB
training/sinatra latest 49d952a36c58 2 years ago 447 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 21 minutes ago 471.2 MB
sinatra vv 7902e96eb014 21 minutes ago 471.2 MB
zane-sinatra vv 7902e96eb014 21 minutes ago 471.2 MB
zane0306/docker-whale latest d09756981eeb 31 hours ago 275.1 MB
centos latest 67591570dd29 11 days ago 191.8 MB
ubuntu latest 104bec311bcd 11 days ago 129 MB
ubuntu 14.04 3f755ca42730 11 days ago 188 MB
hello-world latest c54a2cc56cbb 5 months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb 19 months ago 247 MB
training/webapp latest 6fae60ef3446 19 months ago 348.8 MB
training/sinatra latest 49d952a36c58 2 years ago 447 MB
image摘要
$ docker images --digests | head REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE ouruser/sinatra latest sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf 5db5f8471261 11 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