使用不同的dockerfile从源目录构建docker映像 [英] Building docker images from a source directory using different dockerfiles

查看:198
本文介绍了使用不同的dockerfile从源目录构建docker映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是从同一源代码构建几个不同的docker映像。

My goal is to build several different docker images , from the same source code.

我有我的./src文件夹(node.js项目)。 ./src中的
我有first.dockerfile和第二个dockerfile。

i have my ./src folder (node.js project). inside ./src i have first.dockerfile and second dockerfile.

用于构建项目,我使用此标准命令行

for building the the project i use this standard command line

sudo docker build -t doronaviugy/myproject .

使用默认的 Dockerfile

我正在尝试使用该行从特定的dockerfile中构建

I'm trying to build it from a specific dockerfile using the line

sudo docker build -t doronaviguy/myproject  - <   first.docker

此行有效,但现在路径未在映像内复制

this line works, but now path doesn't being copy inside the image

#Inside the Dockerfile
ADD . /src

我想我知道如何指定dockerfile参数,但是我需要指定direcotry参数

I think i understand how to specify a dockerfile argument, but i need to specify a direcotry argument to be copied inside the docker image.

非常感谢。

推荐答案

从Docker 1.5开始,您可以使用 -f 参数选择要使用的Dockerfile,例如:

Since Docker 1.5, you can use the -f argument to select the Dockerfile to use e.g:

docker build -t doronaviugy / myproject -f dockerfiles / first.docker。

如果您使用stdin构建映像(-< first.docker 语法),您将没有构建上下文,因此将无法使用 COPY ADD 引用本地文件的指令。

If you use stdin to build your image ( the - < first.docker syntax), you won't have a build context so you will be unable to use COPY or ADD instructions that refer to local files.

如果必须使用旧版本的Docker ,您需要使用一些脚本将特定的Dockerfiles复制到构建上下文根目录下的 Dockerfile ,然后调用 docker build

If you have to use an older version of Docker, you'll need to use some scripting to copy your specific Dockerfiles to Dockerfile at the root of the build context before calling docker build.

这篇关于使用不同的dockerfile从源目录构建docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆