Linux入门教程:Docker用户指南(2) – 创建基础镜像, 创建一个Ubunt


使用tar创建一个完整的镜像

一般来说你需要准备一台将在上面打包基础镜像的工作机器,以及不是必要的工具,如Debian的Debootstrap,这个工具也能构建Ubuntu镜像。
创建一个Ubuntu基础镜像很简单:

$ sudo debootstrap raring raring > /dev/null $ sudo tar -C raring -c . | docker import - raring   a29c15f1bf7a   $ docker run raring cat /etc/lsb-release   DISTRIB_ID=Ubuntu DISTRIB_RELEASE=13.04 DISTRIB_CODENAME=raring DISTRIB_DESCRIPTION="Ubuntu 13.04"

在Docker GitHub Repo有更多的示例关于创建基础镜像的:

BusyBox CentOS / Scientific Linux CERN (SLC) on Debian/Ubuntu或on CentOS/RHEL/SLC/etc Debian / Ubuntu

使用scratch创建一个简单的基础镜像

你可以使用Docker自带的,微小的镜像scratch作为构建容器的起点。scratch镜像与你下一个Dockerfile的指令将作为镜像的第一个数据层。
scratch只能在Dockerfile中引用它,不能推送到docker hub或者运行它:

FROM scratch ADD hello / CMD ["/hello"]

hello文件可以到这里下载https://github.com/docker-library/hello-world/tree/master/hello-world

相关内容