本文介绍了创建没有源映像(OS)的Docker映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以使用没有源映像(OS)的docker文件来创建docker映像吗?

  FROM rhel 

我们不希望在所有应用程序docker映像中使用基本映像(centos或rhel)。我们想要将基本映像(centos或rhel)与应用程序映像分开,并在运行时将它们链接起来。



我在构建docker映像时没有 FROM centos rhel ,docker抱怨:在提交前提供源映像



我的docker文件如下:

 维护者abc 

RUN mkdir / opt / cassandra

RUN cd / opt / cassandra

运行wget http://www.interior-dsgn.com/apache/cassandra/2.1.2/apache-cassandra-2.1.2-bin.tar.gz

运行tar xvzf apache-cassandra-2.1.2-bin.tar.gz

RUN cd apache-cassandra-2.1.2-bin


解决方案

您说 我们要分离基本映像(centos或rhel)和应用程序映像,并在运行期间将它们链接。这实际上是 FROM rhel 的工作,这要归功于Docker使用的分层文件系统。



也就是说, FROM 图像不会成为图像的一部分,而是保留在单独的图层中。您的新图像指向该 rhel (或其他 FROM 'd基础层),然后将其自身添加到该基础层上



因此,继续使用 FROM -您将获得所需的行为。

p>

对于那些发现此问题并寻求构建自己基础图像的方式的人(因此您不必使用任何基础图像),可以使用从头开始,您应该阅读有关。



而且,要完全讲究性,Docker之所以需要 FROM 和一个包括Linux发行版的根文件系统在内的基础是,没有根文件系统,就什么也没有。您甚至无法 RUN mkdir / opt / cassandra ,因为 mkdir 是根文件系统提供的程序。 / p>

Can we create a docker image using docker file with out source image (OS) i.e

FROM rhel

We don't want base image(centos or rhel) in all our application docker images. we want to separate base image(centos or rhel) and application images and link them during run time. Is it possible?

When I am building docker image without FROM centos or rhel, docker complains: "provide source image before commit"

My docker file looks like this:

MAINTAINER abc

RUN mkdir /opt/cassandra

RUN cd /opt/cassandra

RUN wget http://www.interior-dsgn.com/apache/cassandra/2.1.2/apache-cassandra-2.1.2-bin.tar.gz

RUN tar xvzf apache-cassandra-2.1.2-bin.tar.gz

RUN cd apache-cassandra-2.1.2-bin
解决方案

You said "we want to separate base image(centos or rhel) and application images and link them during run time." That is essentially what FROM rhel does, thanks to the layered file systems used by Docker.

That is, the FROM image does not become part of your image -- it remains in a separate layer. Your new image points to that rhel (or other FROM'd base layer) and then adds itself on top of it at runtime.

So go ahead and use FROM -- you'll get the behavior you wanted.

For those that find this question looking for a way to build their own base image (so you don't have to use anything as a base), you can use FROM scratch and you should read about Creating a base image.

And, to be completely pedantic, the reason why Docker needs a FROM and a base including a Linux distribution's root file system is that without a root file system, there is nothing. You can't even RUN mkdir /opt/cassandra because mkdir is a program provided by the root file system.

这篇关于创建没有源映像(OS)的Docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 09:31