一、安装docker
yum install epel-resase
yum install docker-io (RHEL6)
yum install docker (RHEL7)
系统:
[root@kvm ~]# uname -a
Linux kvm.huangming.org 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@kvm ~]# cat /etc/issue
CentOS release 6.7 (Final)
Kernel \r on an \m
二、启动docker
1 2 3 4 5 6 |
|
三、镜像管理
-
docker pull centos
#从docker.com获取centos镜像
-
docker images
#查看本地镜像
-
docker tag centos test-img
#为centos镜像设置标签为test-img,在使用docker image查看时会多出一行,更改的image id和centos的一样
-
docker search [image-name]
#搜索docker仓库里的docker镜像
-
docker run -t -i centos /bin/bash
#用下载到的镜像开启容器,-i表示让容器的标准输入打开,-t表示分配一个伪终端,要把-i -t放到镜像名字的前面。当镜像发生修改后,我们可以把该镜像提交重新生成一个新版本运行在本地
-
docker ps
#查看运行的容器,加-a选项可以查看没有运行的容器
-
docker rmi centos
#用来删除指定的镜像,其中后面的参数可以是tag,如果是tag时,实际上是删除该tag,只要该镜像还有其他的tag,就不会删除该镜像。当后面的参数为ID时,则会彻底删除整个镜像,连同所有的标签。
1、下载centos镜像
1 2 3 4 5 6 7 8 |
|
2、查看下载到本地镜像
1 2 3 |
|
3、查看docker仓库镜像
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
4、开启一个容器docker run -it centos /bin/bash
1 2 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
1 2 3 4 |
|
5、修改镜像名称
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
6、删除镜像
1 2 3 4 5 6 |
|
四、docker镜像使用容器生成新的镜像
1、启动镜像
1 2 3 4 5 6 |
|
2、进入已启动的容器docker exec -it 【镜像ID,可以简写】 /bin/bash
1 2 |
|
3、在容器中安装软件(安装网卡包net-tools)
[root@8c1fd812d079 /]# yum install net-tools wget -y
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
4、生成新的镜像
-
docker commit -m "change somth" -a "somebody info" container_id new-image
例如:docker commit -m "install httpd" -a "test-image1" 8c1fd812d079 test/centos
1 2 3 4 5 6 7 |
|
五、docker基于本地模版导入创建镜像
1、下载地址https://download.openvz.org/template/precreated/
2、下载一个镜像模版
-
导入镜像
#cat centos-6-x86_64-minimal.tar.gz | docker import - centos-6-x86_64
-
导出镜像
#docker save -o new-centos.tar new-image/centos
-
恢复本地镜像
#docker load --input new-centos.tar 或者 docker load < new-centos.tar
-
上传镜像到dockerhub官网,前提需要注册一个用户
#docker push image-name
3、导入镜像
1 2 |
|
-
查看镜像
1 2 3 4 5 6 |
|
4、导出镜像
1 2 3 |
|
5、强制删除镜像
1 2 3 |
|
6、恢复镜像
1 2 3 4 5 6 7 8 9 10 11 |
|