如何下载基地docker工人图像来创buildhello worlddocker图像?

我在docker工人的起始位置。 我正在尝试创build需要一些基本图像的helloworld docker镜像。 我在内联网工作。 那么,我怎样才能获得基础图像? 我正在使用Redhat Linux 7。

Docker会自动下载您在Dockerfile中指定的基础映像。 所以,例如,一个非常简单的“你好,世界”的形象可能是;

你的Dockerfile的内容:

FROM alpine CMD echo "hello-world" 

从Dockerfile构build一个映像,并将其命名为“hello”:

 docker build -t hello . 

你会看到Docker拉alpine图像,如果它还没有,然后build立图像;

 Sending build context to Docker daemon 2.048 kB Step 1 : FROM alpine ---> 70c557e50ed6 Step 2 : CMD echo "hello world" ---> Running in 94fcb9b89aaa ---> 6462a272b1d6 Removing intermediate container 94fcb9b89aaa Successfully built 6462a272b1d6 

然后你可以从图像中运行一个容器(这个图像只会运行,并在完成后直接退出)

 $ docker run hello hello world 

您可以将任何图像用作自己图像的“基础”( FROM )图像,因此您在Docker Hub上find的任何图像都可以用作基础。

但是,一般来说,build议使用“官方”图像作为自己的图像的基础。 有各种各样的“发行版”,如Ubuntu,Debian,Alpine(如果你想要一个轻量级的图像),CentOS等。基本的图像不必与主机的发行版相匹配(所以你可以使用“ubuntu”即使您的主机上运行有Red Hat,也是为了您的映像)

你可以在这里find官方的图片。 https://hub.docker.com/explore/

对于更高级的“hello world”图片,请参阅这里的文档; https://docs.docker.com/engine/userguide/containers/dockerizing/

和编写Dockerfiles的最佳实践; https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/

使用tar创build一个完整的图像

一般来说,你需要从一台运行你想要打包的发行版的工作机器开始,但是Debian的Debootstrap这样的工具并不是必需的,你也可以用它来构buildUbuntu镜像。

创build一个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中有更多的示例脚本来创build基础图像:

  • 红帽企业Linux

  • BusyBox的

  • Debian / Ubuntu