pom 发表于 2015-10-13 08:38:45

Docker 使用方法总结之:镜像


[*]查找
命令:docker search TERM
相关参数:
Search the Docker Hub for images
--automated=false    Only show automated builds
--no-trunc=false   Don't truncate output
-s, --stars=0      Only displays with at least x stars
例子:
# docker search mysql
NAME                         DESCRIPTION                                     STARS   OFFICIAL   AUTOMATED
mysql                        MySQL is a widely used, open-source relati...   655             
tutum/mysql                  MySQL Server image - listens in port 3306....   115                  
orchardup/mysql                                                            37                  
centurylink/mysql            Image containing mysql. Optimized to be li...   21                  
...................

[*]获取
命令:docker pull NAME[:TAG]
参数:-a, --all-tags=false    Download all tagged images in the repository
例子:
# docker pull tutum/mysql
Pulling repository tutum/mysql
26c0c52dc79a: Pulling dependent layers
511136ea3c5a: Download complete
27d47432a69b: Download complete
5f92234dcf1e: Download complete
51a9c7c1f8bb: Download complete
5ba9dab47459: Download complete
d26d9affc74e: Download complete
c8420faa4614: Download complete
.........

[*]运行image
命令:docker run -t -i tutum/mysql /bin/bash

[*]查看列表
命令:docker images
参数
-a, --all=false      Show all images (by default filter out the intermediate image layers)
-f, --filter=[]      Provide filter values (i.e. 'dangling=true')
--no-trunc=false   Don't truncate output
-q, --quiet=false    Only show numeric IDs
例子
# docker images -a
REPOSITORY            TAG               IMAGE ID            CREATED             VIRTUAL SIZE
<none>                <none>            6941bfcbbfca      10 days ago         0 B
eric/ubuntu         latest            52671e55fb86      6 weeks ago         270.3 MB
<none>                <none>            c8420faa4614      3 months ago      192.7 MB
<none>                <none>            d26d9affc74e      3 months ago      192.7 MB
<none>                <none>            5ba9dab47459      3 months ago      192.7 MB
[*]更改TAG
更改之前:
# docker images
REPOSITORY            TAG               IMAGE ID            CREATED             VIRTUAL SIZE
centos                7                   fd44297e2ddb      10 days ago         229.6 MB
centos                centos7             fd44297e2ddb      10 days ago         229.6 MB
centos                latest            fd44297e2ddb      10 days ago         229.6 MB
eric/ubuntu         latest            52671e55fb86      6 weeks ago         270.3 MB
tutum/mysql         latest            26c0c52dc79a      3 months ago      322.5 MB
centos_6_5            ansible             f01c1b138488      10 months ago       322.4 MB
chug/ubuntu12.10x64   latest            0b96c14dafcd      13 months ago       270.3 MB
执行命令:
docker tag tutum/mysql:latest localrepo:newtag
更改之后:
# docker images
REPOSITORY            TAG               IMAGE ID            CREATED             VIRTUAL SIZE
centos                7                   fd44297e2ddb      10 days ago         229.6 MB
centos                centos7             fd44297e2ddb      10 days ago         229.6 MB
centos                latest            fd44297e2ddb      10 days ago         229.6 MB
eric/ubuntu         latest            52671e55fb86      6 weeks ago         270.3 MB
tutum/mysql         latest            26c0c52dc79a      3 months ago      322.5 MB
localrepo             newtag            26c0c52dc79a      3 months ago      322.5 MB
centos_6_5            ansible             f01c1b138488      10 months ago       322.4 MB
chug/ubuntu12.10x64   latest            0b96c14dafcd      13 months ago       270.3 MB

[*]查看明细
命令:docker inspect CONTAINER|IMAGE
参数:-f, --format=&quot;&quot;    Format the output using the given go template.
例子:
# docker inspect f01c1b138488

[*]删除
命令:docker rmi IMAGE
参数:
-f, --force=false    Force removal of the image
--no-prune=false   Do not delete untagged parents
例子:
# docker rmi 26c
Error response from daemon: Conflict, cannot delete 26c0c52dc79a because the container 002ca178e599 is using it, use -f to force
上面出错的原因是因为该镜像正在被002ca178e599的容器使用,所以不能删除,所以首先需要使用docker rm删除容器,然后再删除,相关的AUFS文件也会被删除
# docker rm 002
002
# docker rmi 26c
Untagged: localrepo:newtag
Deleted: 26c0c52dc79af8acf07a18cd1693bfae91926f496ee4d1c1dbe29a014394b7c0
Deleted: ba600267bf1a82675eeee78a2e18c49306c46888ca3cf33f372be4b80334d4f0
Deleted: 6d79a1795e744a9c2c4409526f90c9711d96d0e944a7f485fc31acf7e44fb210
Deleted: cb6a06a808d4329b1bba405b9e3e733b1c379fb55979e8631e918f6c14c6023a
Deleted: 8d466d27bccad3502d579a2e0e6fc28fa8a46e32b5b453e7387a61eef7c1be8a
......

[*]创建
由于

[*]基于Container创建

[*]启动一个容器
# docker run -ti f01 /bin/bash
[*]在启动的容器中安装ansible,git等工具

[*]查询Container ID
# docker ps
CONTAINER ID      IMAGE                COMMAND             CREATED             STATUS            PORTS               NAMES
52ec71824717      centos_6_5:ansible   &quot;/bin/bash&quot;         31 seconds ago      Up 30 seconds                           high_mcclintock

[*]执行创建命令,返回值就是生成的Image ID
# docker commit -m 'Ansible Image,and git, sample yml files' -a 'Eric.sunah' 52ec71824717 eric/ansible
6e3832e7c6e1aba47aefe1430c346a1dbf9a0454c37a907d293eaf7056d11d91
[*]查看新的列表
# docker images
REPOSITORY            TAG               IMAGE ID            CREATED             VIRTUAL SIZE
eric/ansible          latest            6e3832e7c6e1      2 minutes ago       629.7 MB
eric/ubuntu         latest            52671e55fb86      6 weeks ago         270.3 MB
centos_6_5            ansible             f01c1b138488      10 months ago       322.4 MB
chug/ubuntu12.10x64   latest            0b96c14dafcd      13 months ago       270.3 MB


[*]另存为
命令:docker save IMAGE
参数:-o, --output=&quot;&quot;    Write to a file, instead of STDOUT
例子:
docker save -o centos6_ansible.tar eric/ansible

[*]导入
命令:docker load
参数:   -i, --input=&quot;&quot;   Read from a tar archive file, instead of STDIN
例子:
docker load --input centos6_ansible.tar

[*]上传
首先取个便于识别的TAG
# docker tag 6e38 sun7545526/template:ansible
# docker images
REPOSITORY            TAG               IMAGE ID            CREATED             VIRTUAL SIZE
sun7545526/template   ansible             6e3832e7c6e1      17 minutes ago      629.7 MB
eric/ansible          latest            6e3832e7c6e1      17 minutes ago      629.7 MB

执行上传命令,第一次上传的时候会要求输入用户名,密码,邮箱信息:
# docker push sun7545526/template:ansible
The push refers to a repository (len: 1)
Sending image list
Pushing repository sun7545526/template (1 tags)
511136ea3c5a: Image already pushed, skipping
1d6ebc5c68b1: Image already pushed, skipping
f01c1b138488: Image already pushed, skipping
6e3832e7c6e1: Image successfully pushed
Pushing tag for rev on {https://cdn-registry-1.docker.io/v1/repositories/sun7545526/template/tags/ansible}
         版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: Docker 使用方法总结之:镜像