尝试使用由我构建的另一个自定义镜像(Y)构建docker镜像(X)。在这里,我正尝试将文件夹从基本图像Y复制到X,如下所示。
FROM some-image as base
COPY --from=base /root/.m2 /root
RUN mkdir -p /build
但这会引发错误
invalid from flag value base: pull access denied for base, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
我该如何实现?
最佳答案
您不是从某个基本镜像中应对,而是尝试在同一镜像中进行复制。
You need to have a second stage to use COPY --from you can not point --from to the same stage you are currently changing.
docker-cli-issues/1559
这是最简单的例子
结果是
FROM alpine as build-env
RUN apk add --no-cache build-base
WORKDIR /app
COPY . .
# Compile the binaries
RUN gcc -o hello helloworld.c
FROM alpine
COPY --from=build-env /app/hello /app/hello
WORKDIR /app
CMD ["/app/hello"]
你好ç
# include <stdio.h>
int main(){
printf("Hello World!");
return 0;
}
关于docker - 将文件从基础图像复制到当前建筑物图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58370581/