1、下载centos镜像
[root@kvm ~]# docker pull centos
latest: Pulling from centos
47d44cb6f252: Already exists
6fdebd7b0eb5: Already exists
a63aae4d216f: Already exists
Digest: sha256:381f21e4c7b3724c6f420b2bcfa6e13e47ed155192869a2a04fa10f944c78476
Status: Image is up to date for centos:latest 2、查看下载到本地镜像
[root@kvm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos latest bb3d629a7cbc 3 weeks ago 196.6 MB 3、查看docker仓库镜像
[root@kvm ~]# docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 2069 [OK]
jdeathe/centos-ssh CentOS-6 6.7 x86_64 / CentOS-7 7.2.1511 x8... 18 [OK]
jdeathe/centos-ssh-apache-php CentOS-6 6.7 x86_64 / Apache / PHP / PHP M... 14 [OK]
million12/centos-supervisor Base CentOS-7 with supervisord launcher, h... 10 [OK]
blalor/centos Bare-bones base CentOS 6.5 image 8 [OK]
nimmis/java-centos This is docker images of CentOS 7 with dif... 8 [OK]
torusware/speedus-centos Always updated official CentOS docker imag... 7 [OK]
centos/mariadb55-centos7 3 [OK]
nathonfowlie/centos-jre Latest CentOS image with the JRE pre-insta... 3 [OK]
nickistre/centos-lamp LAMP on centos setup 3 [OK]
consol/sakuli-centos-xfce Sakuli end-2-end testing and monitoring co... 2 [OK]
softvisio/centos Centos 1 [OK]
layerworx/centos CentOS container with etcd, etcdctl, confd... 1 [OK]
yajo/centos-epel CentOS with EPEL and fully updated 1 [OK]
lighthopper/orientdb-centos A Dockerfile for creating an OrientDB imag... 1 [OK]
darksheer/centos Base Centos Image -- Updated hourly 1 [OK]
timhughes/centos Centos with systemd installed and running 1 [OK]
januswel/centos yum update-ed CentOS image 0 [OK]
drokar/centos-s6 centOS combined with s6, a small process s... 0 [OK]
lighthopper/openjdk-centos A Dockerfile for creating an OpenJDK image... 0 [OK]
ustclug/centos USTC centos 0 [OK]
blacklabelops/centos CentOS Base Image! Built and Updates Daily! 0 [OK]
grayzone/centos auto build for centos. 0 [OK]
jsmigel/centos-epel Docker base image of CentOS w/ EPEL installed 0 [OK]
grossws/centos CentOS 6 and 7 base images with gosu and l... 0 [OK]
4、开启一个容器docker run -it centos /bin/bash
[root@kvm ~]# docker run -it centos /bin/bash
[root@8c1fd812d079 /]#
[root@8c1fd812d079 /]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@8c1fd812d079 /]# uname -a
Linux 8c1fd812d079 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@8c1fd812d079 /]# w
11:55:12 up 42 min, 0 users, load average: 0.00, 0.03, 0.01
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
[root@8c1fd812d079 /]# ps
PID TTY TIME CMD
1 ? 00:00:00 bash
16 ? 00:00:00 ps
[root@8c1fd812d079 /]# uptime
11:55:21 up 42 min, 0 users, load average: 0.00, 0.02, 0.01
[root@8c1fd812d079 /]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/docker-8:3-1573967-8c1fd812d0790d1868bcec389a50c6f7a08c6c099167141393af0961e7b850be ext4 9.8G 230M 9.0G 3% /
tmpfs tmpfs 1.9G 0 1.9G 0% /dev
shm tmpfs 64M 0 64M 0% /dev/shm
/dev/sda3 ext4 43G 4.6G 36G 12% /etc/hosts
[root@8c1fd812d079 /]# exit
[root@kvm ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f732106147eb centos "/bin/bash" 17 seconds ago Up 15 seconds high_heisenberg
8c1fd812d079 centos "/bin/bash" 3 minutes ago Exited (0) About a minute ago grave_mcclintock
5、修改镜像名称
[root@kvm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos latest bb3d629a7cbc 3 weeks ago 196.6 MB
[root@kvm ~]# docker tag centos test-img
[root@kvm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos latest bb3d629a7cbc 3 weeks ago 196.6 MB
test-img latest bb3d629a7cbc 3 weeks ago 196.6 MB
[root@kvm ~]# docker tag test-img centos:test-img2
[root@kvm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
test-img latest bb3d629a7cbc 3 weeks ago 196.6 MB
centos latest bb3d629a7cbc 3 weeks ago 196.6 MB
centos test-img2 bb3d629a7cbc 3 weeks ago 196.6 MB
6、删除镜像
[root@kvm ~]# docker rmi centos:test-img2
Untagged: centos:test-img2
[root@kvm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos latest bb3d629a7cbc 3 weeks ago 196.6 MB
test-img latest bb3d629a7cbc 3 weeks ago 196.6 MB
四、docker镜像使用容器生成新的镜像
1、启动镜像
[root@kvm ~]# docker start 8c1fd
8c1fd
[root@kvm ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f732106147eb centos "/bin/bash" 12 minutes ago Exited (0) 43 seconds ago high_heisenberg
8c1fd812d079 centos "/bin/bash" 15 minutes ago Up 3 seconds 2、进入已启动的容器docker exec -it 【镜像ID,可以简写】 /bin/bash
[root@kvm src]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos-6-x86_64 latest 1014358cbf3b About a minute ago 326.4 MB
centos_new1 latest 3e4be15719e0 24 hours ago 268 MB
test-img latest bb3d629a7cbc 3 weeks ago 196.6 MB
centos latest bb3d629a7cbc 3 weeks ago 196.6 MB 4、导出镜像
[root@kvm src]# docker save -o centos_net_01.tar bb3d629a7cbc
[root@kvm src]# du -sh centos_net_01.tar
195Mcentos_net_01.tar 5、强制删除镜像
[root@kvm src]# docker rmi -f bb3d629a7cbc
Untagged: centos:latest
Untagged: test-img:latest 6、恢复镜像
[root@kvm src]# docker load < centos_net_img2.tar
[root@kvm src]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos-6-x86_64 latest 1014358cbf3b 18 minutes ago 326.4 MB
<none> <none> 3e4be15719e0 24 hours ago 268 MB
[root@kvm src]# docker tag 3e4be15719e0 centos_net_img:latest
[root@kvm src]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos-6-x86_64 latest 1014358cbf3b 21 minutes ago 326.4 MB
centos_net_img latest 3e4be15719e0 24 hours ago 268 MB