首页 > 学院 > 操作系统 > 正文

自制docker basic image

2024-06-28 13:24:39
字体:
来源:转载
供稿:网友
自制docker basic image

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 - tanghuimin0713/ubuntu_i386

完成之后通过docker images命令可以看到刚才创建的image文件

root@ubuntu:/home/thm/docker/min_os/ubuntu_i386# docker imagesREPOSITORY                   TAG                 IMAGE ID            CREATED              VIRTUAL SIZEtanghuimin0713/ubuntu_i386   latest              ee57f53fe012        About a minute ago   216.8 MBubuntu                       14.04.1             c4ff7513909d        8 days ago           225.4 MBubuntu                       latest              c4ff7513909d        8 days ago           225.4 MBubuntu                       14.04               c4ff7513909d        8 days ago           225.4 MBubuntu                       trusty              c4ff7513909d        8 days ago           225.4 MB

4. 修改basic image的tag

docker tag ee57f53fe012 tanghuimin0713/ubuntu_i386:14.04

ee57f53fe012是image id,tanghuimin0713/ubuntu_i386:14.04是respository名:tag名

root@ubuntu:/home/thm/docker/min_os/ubuntu_i386# docker tag ee57f53fe012 tanghuimin0713/ubuntu_i386:14.04root@ubuntu:/home/thm/docker/min_os/ubuntu_i386# root@ubuntu:/home/thm/docker/min_os/ubuntu_i386# docker imagesREPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZEtanghuimin0713/ubuntu_i386   latest              ee57f53fe012        6 minutes ago       216.8 MBtanghuimin0713/ubuntu_i386   14.04               ee57f53fe012        6 minutes ago       216.8 MBubuntu                       latest              c4ff7513909d        8 days ago          225.4 MBubuntu                       14.04               c4ff7513909d        8 days ago          225.4 MBubuntu                       14.04.1             c4ff7513909d        8 days ago          225.4 MBubuntu                       trusty              c4ff7513909d        8 days ago          225.4 MB

5. 将新建的basic image上传到docker hub中共享

docker push tanghuimin0713/ubuntu_i386

root@ubuntu:/home/thm/docker/min_os/ubuntu_i386# docker push tanghuimin0713/ubuntu_i386The push refers to a repository [tanghuimin0713/ubuntu_i386] (len: 2)Sending image listPushing repository tanghuimin0713/ubuntu_i386 (2 tags)ee57f53fe012: Pushing [======================================>            ] 176.8 MB/232.1 MB 4m0s

备注:要想把自制的image文件上传到docker hub中与全世界的开发者共享需要先在docker hub中注册一个帐号,上传命令是docker push 用户名/image名。下图是我在docker hub的账户界面:


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表