docker對鏡像的相關操做

1、建立鏡像git

在現有鏡像的基礎上啓動一個容器
docker

[root@docker ~]# docker p_w_picpaths
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              centos7             7322fbe74aa5        6 days ago          172.2 MB
centos              centos6.6           8b44529354f3        9 weeks ago         202.6 MB
[root@docker ~]# docker run -t -i centos:centos6.6 /bin/bash
[root@06ba542f19c9 /]# hostname
06ba542f19c9        #這個是容器ID,惟一值

在容器中添加一個httpd服務
centos

[root@06ba542f19c9 /]# rpm -qa  |grep httpd
[root@06ba542f19c9 /]# yum install httpd -y
[root@06ba542f19c9 /]# rpm -qa |grep httpd
httpd-tools-2.2.15-39.el6.centos.x86_64
httpd-2.2.15-39.el6.centos.x86_64
[root@06ba542f19c9 /]# exit
exit

在咱們使用exit退出後,容器已經被咱們改變了,使用docker commit來提交新的信息
bash

[root@docker ~]# docker commit -m "add httpd" -a "root" 06ba542f19c9 centos:centos6.6_v1
ae2ffc5dbfcc7944a624c55bc081b9514c83b420450d1ea9c67afc0b677bd686
#-m     來指定提交的說明信息
#-a     能夠指定更新的用戶信息
#06ba542f19c9 這是咱們上面啓動容器後生成的ID
#centos:centos6.6_v1    前面的一部分表示那個repo,後面的一部分表示TAG

#查看提交後的結果
[root@docker ~]# docker p_w_picpaths
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              centos6.6_v1        ae2ffc5dbfcc        9 seconds ago       274.2 MB
centos              centos7             7322fbe74aa5        6 days ago          172.2 MB
centos              centos6.6           8b44529354f3        9 weeks ago         202.6 MB

咱們使用新建立的鏡像來啓動容器
ide

[root@docker ~]# docker run -t -i centos:centos6.6_v1 /bin/bash
[root@5fc242e53248 /]# hostname 
5fc242e53248
[root@5fc242e53248 /]# rpm -qa |grep httpd        #在前面添加的httpd也存在
httpd-tools-2.2.15-39.el6.centos.x86_64
httpd-2.2.15-39.el6.centos.x86_64

在上面的例子中咱們是使用的docker commit來建立的鏡像,下面咱們使用dockerfile來建立鏡像ui

[root@docker git]# mkdir git
[root@docker git]# cd git
[root@docker git]# cat Dockerfile 
FROM centos:centos6.6        #已哪一個鏡像做爲基礎
MAINTAINER lyao              #維護者的信息
RUN yum install git  -y           #要安裝的軟件包
[root@docker git]# docker build -t "git" .    #-t 添加註釋

#查看結果
[root@docker git]# docker p_w_picpaths
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
#新添加的鏡像
git                 latest              8aa77ab9e593        6 minutes ago       301.1 MB
centos              centos6.6_v1        ae2ffc5dbfcc        4 days ago          274.2 MB
centos              centos7             7322fbe74aa5        11 days ago         172.2 MB
centos              centos6.6           8b44529354f3        9 weeks ago         202.6 MB
相關文章
相關標籤/搜索