[英]Issues with COPY when using multistage Dockerfile builds — no such file or directory
I'm trying to convert my project to use multi-stage builds. 我正在尝试将我的项目转换为使用多阶段构建。 However, the final step always fails with an error:
但是,最后一步总是失败并显示错误:
Step 11/13 : COPY --from=build /bin/grafana-server /bin/grafana-server
COPY failed: stat /var/lib/docker/overlay2/xxxx/merged/bin/grafana-server: no such file or directory
My Dockerfile looks like this: 我的Dockerfile看起来像这样:
FROM golang:latest AS build
ENV SRC_DIR=/go/src/github.com/grafana/grafana/
ENV GIT_SSL_NO_VERIFY=1
COPY . $SRC_DIR
WORKDIR $SRC_DIR
# Building of Grafana
RUN \
npm run build && \
go run build.go setup && \
go run build.go build
# Create final stage containing only required artifacts
FROM scratch
COPY --from=build /bin/grafana-server /bin/grafana-server
EXPOSE 3001
CMD ["./bin/grafana-server"]
The build.go build
step will output artifacts to ./bin/
-- The error is pretty unhelpful other than telling me the files don't exist where I think they should exist. build.go build
步骤将把工件输出到./bin/
-该错误非常./bin/
,除了告诉我文件不存在的地方外,我认为它们应该存在。
My folder structure on my machine is: 我的机器上的文件夹结构是:
--| ~/Documents/dev/grafana/src/grafana/grafana
--------| bin
------------| <grafan-server builds to here>
--------| deploy
------------| docker
----------------| Dockerfile
From ~/Documents/dev/grafana/src/grafana/grafana
is where I issue: docker build -t grafana -f deploy/docker/Dockerfile .
我从
~/Documents/dev/grafana/src/grafana/grafana
发布: docker build -t grafana -f deploy/docker/Dockerfile .
To follow-up my comment, the path you set with the WORKDIR
is absolute and should be specified in the same way in the COPY --from=build
command. 为了跟进我的评论,用
WORKDIR
设置的路径是绝对路径,应该在COPY --from=build
命令中以相同的方式指定。
So this could lead to the following Dockerfile: 因此,这可能会导致以下Dockerfile:
FROM golang:latest AS build
ENV SRC_DIR=/go/src/github.com/grafana/grafana/
ENV GIT_SSL_NO_VERIFY=1
COPY . $SRC_DIR
WORKDIR $SRC_DIR
# Building of Grafana
RUN \
npm run build && \
go run build.go setup && \
go run build.go build
# Create final stage containing only required artifacts
FROM scratch
ENV SRC_DIR=/go/src/github.com/grafana/grafana/
WORKDIR $SRC_DIR
COPY --from=build ${SRC_DIR}/bin/grafana-server ${SRC_DIR}/bin/grafana-server
EXPOSE 3001
CMD ["./bin/grafana-server"]
(only partially tested) (仅部分测试)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.