首先将镜像挂载在本地
[root@zhangxc image]# cat /etc/fstab
/media/sf_Centos/iso/CentOS-6.6-x86_64-bin-DVD1.iso /mnt/iso iso9660
defaults,loop 0 0
制作镜像
[root@zhangxc image]# febootstrap -i bash -i tar -i openssh-server -i
yum -i iputils -i iproute -i vim centos6 centos6-image file:///mnt/iso
或者
febootstrap -i bash -i wget -i yum -i iputils -i iproute -i man -i
vim-minimal -i openssh-server -i openssh-clients centos6 centos6-image
http://mirrors.aliyun.com/centos/6/os/x86_64/
[root@zhangxc image]# ls
centos6-image
[root@zhangxc image]cd centos6-image/
[root@zhangxc centos6-image]# tar -c .|docker import - centos6-base
9857a3807fd4764016e2f5b30bb95bdb71dfe97a2bf74acdd6e947ef3561794e
[root@zhangxc centos6-image]# docker images //成功
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos6-base latest 9857a3807fd4 7 minutes ago 370.9 MB
启动
[root@zhangxc centos6-image]# docker run -i -t centos6-base /bin/bash
bash-4.1# ls
this finsihed
可能出现的问题:
bash-4.1#
解决:
bash-4.1$
这就代表是普通用户啊
超级用户的标志是#, 普通用户是$
[root@zhangxc centos6-image]# docker run -it zhangxc/centos:base /bin/bash
bash-4.1# su -
[root@de1e42e1bc43 ~]#
vi ~/.bash_profile
编辑这个文件,有时会提示这个文件不存在,直接选edit。
在文件加上
export PS1='[\u@\h \W]\$'
在ssh中vi的保存先按ESC,然后:wq! 保存退出。
最后执行
source ~/.bash_profile
这时shell就可以显示路径了
参考链接http://www.bkjia.com/Linux/884121.html
导出镜像和导入镜像方便分享镜像文件
导出镜像:
docker save IMAGENAME | bzip2 -9 -c>img.tar.bz2
导入镜像(换一台机器):
bzip2 -d -c <img.tar.bz2 | docker load