docker的安装和入门见官网教程:http://docs.docker.com/
下面是自制docker basic image的步骤,以ubuntu为例。
1. 安装debootstrap
apt-get install debootstrap
2. 创建基本系统
debootstrap --arch=i386 trusty /home/thm/docker/min_os/ubuntu_i386/ http://archive.ubuntu.com/ubuntu
arch后跟的是硬件架构名称,可以是:amd64
, armel
, armhf
, i386
, ia64
, mips
, mipsel
, powerpc
, s390
, s390x
, sparc等。
"/home/thm/docker/min_os/ubuntu_i386/"是我存放ubuntu文件系统的地方,此目录可以根据实际情况修改。
3. 创建文件系统镜像
cd /home/thm/docker/min_os/ubuntu_i386/
tar -c . | docker import - tang*0713/ubuntu_i386
完成之后通过docker images命令可以看到刚才创建的image文件
root@ubuntu:/home/thm/docker/min_os/ubuntu_i386# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
tang*0713/ubuntu_i386 latest ee57f53fe012 About a minute ago 216.8 MB
ubuntu 14.04. c4ff7513909d days ago 225.4 MB
ubuntu latest c4ff7513909d days ago 225.4 MB
ubuntu 14.04 c4ff7513909d days ago 225.4 MB
ubuntu trusty c4ff7513909d days ago 225.4 MB
4. 修改basic image的tag
docker tag ee57f53fe012 tang*0713/ubuntu_i386:14.04
ee57f53fe012是image id,tang*0713/ubuntu_i386:14.04是respository名:tag名
root@ubuntu:/home/thm/docker/min_os/ubuntu_i386# docker tag ee57f53fe012 tang*0713/ubuntu_i386:14.04
root@ubuntu:/home/thm/docker/min_os/ubuntu_i386#
root@ubuntu:/home/thm/docker/min_os/ubuntu_i386# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
tang*0713/ubuntu_i386 latest ee57f53fe012 6 minutes ago 216.8 MB
tang*0713/ubuntu_i386 14.04 ee57f53fe012 6 minutes ago 216.8 MB
ubuntu latest c4ff7513909d days ago 225.4 MB
ubuntu 14.04 c4ff7513909d days ago 225.4 MB
ubuntu 14.04. c4ff7513909d days ago 225.4 MB
ubuntu trusty c4ff7513909d days ago 225.4 MB
5. 将新建的basic image上传到docker hub*享
docker push tang*0713/ubuntu_i386
root@ubuntu:/home/thm/docker/min_os/ubuntu_i386# docker push tang*0713/ubuntu_i386
The push refers to a repository [tang*0713/ubuntu_i386] (len: )
Sending image list
Pushing repository tang*0713/ubuntu_i386 ( tags)
ee57f53fe012: Pushing [======================================> ] 176.8 MB/232.1 MB 4m0s
备注:要想把自制的image文件上传到docker hub中与全世界的开发者共享需要先在docker hub中注册一个帐号,上传命令是docker push 用户名/image名。下图是我在docker hub的账户界面: