Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Docker构建参数和副本_Docker - Fatal编程技术网

Docker构建参数和副本

Docker构建参数和副本,docker,Docker,尝试复制文件夹内容时,当我硬编码路径时,它会起作用,如下所示: COPY ./my-folder /path/to/location 但需要能够更改此路径,所以我尝试使用如下构建参数: COPY ${folderVariable} /path/to/location ARG docsBranch=4.5 ARG docsFullPath=registry.myCompany.pro/group/project-docs/docs:$docsBranch # Lifehack FROM $d

尝试复制文件夹内容时,当我硬编码路径时,它会起作用,如下所示:

COPY ./my-folder /path/to/location
但需要能够更改此路径,所以我尝试使用如下构建参数:

COPY ${folderVariable} /path/to/location
ARG docsBranch=4.5
ARG docsFullPath=registry.myCompany.pro/group/project-docs/docs:$docsBranch

# Lifehack
FROM $docsFullPath as docs

FROM node:10.21.0-buster-slim
WORKDIR /app

# Now we can use docs instead of $docsFullPath
COPY --from=docs /app/html/en ./documentation/en
然后用

--build-arg folderVariable=./my-folder

但它会将所有内容复制到与“我的文件夹”相同的文件夹中,当我只需要“我的文件夹”的内容时,您需要在使用以下文件之前,使用
Dockerfile
中的
ARG
对其进行定义:

FROM alpine:3.3

ARG folderVariable=./my-folder # Optional default value to be `./my-folder`

COPY ${folderVariable} /opt/my-folder
然后像这样构建它:

docker build --build-arg folderVariable=./folder-copy -t test .

更多详细信息请参阅:

对于
复制--from=$var…
案例,扩展仍然不起作用。 但您可以创建中间映像作为别名,如下所示:

COPY ${folderVariable} /path/to/location
ARG docsBranch=4.5
ARG docsFullPath=registry.myCompany.pro/group/project-docs/docs:$docsBranch

# Lifehack
FROM $docsFullPath as docs

FROM node:10.21.0-buster-slim
WORKDIR /app

# Now we can use docs instead of $docsFullPath
COPY --from=docs /app/html/en ./documentation/en

这在以前可能有效,但在当前docker版本(19.03.4)中,“生成”参数似乎没有按预期展开。@Emil,您有多阶段生成吗?在单阶段构建(19.03.5或18)中,似乎不会在COPY语句的--from参数中展开。请注意,
ARG
具有作用域()。我已经挣扎了好几个小时:PI也有同样的问题,我更新了docker,将ARG移到表单后面,然后我还看到我的ARG有前导空格,这干扰了copy命令。