复制文件而不是Dir,在Docker 2阶段构建中使用相同名称
在以下dockerfile
中,
WORKDIR /app
RUN go build -ldflags "-s -w" -a -installsuffix cgo -o tool-web ./tool-web
...
FROM scratch
COPY --from=build /app/tool-web /app/tool-web
复制
指令复制Directory tool> tool-web
而不是二进制。
是否有一种方法可以指定要复制二进制文件的复制?
In the following Dockerfile
WORKDIR /app
RUN go build -ldflags "-s -w" -a -installsuffix cgo -o tool-web ./tool-web
...
FROM scratch
COPY --from=build /app/tool-web /app/tool-web
turns out the COPY
directive copies the directory tool-web
and not the binary.
Is there a way to specify to the COPY
that the binary is to be copied?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据
go
命令 documentationation :因此,如果您使用
-o tool-web
和./ tool-web/
是现有目录,则输出二进制文件将以>中的文件写入工具-Web
目录。一个不错的猜测是您的二进制可能已安装为./ tool-web/main
。为了解决此问题,两种简单的方法是:
复制
以将该路径用作源复制-from = build/app/tool-web/main/app/tool-web
-O
以写入其他文件名,然后调整复制
将该名称用作源-o tool-web-binary
复制-from = build/app/tool-web-binary/app/tool-web
Per the
go
command documentation:Thus, if you use
-o tool-web
and./tool-web/
is an existing directory, your output binary will be written as a file within thetool-web
directory. A decent guess is your binary may have been installed as./tool-web/main
.To fix this, two easy approaches would be:
COPY
to use that path as the sourceCOPY --from=build /app/tool-web/main /app/tool-web
-o
to write to a different filename, and then adjustCOPY
to use that name as the source-o tool-web-binary
COPY --from=build /app/tool-web-binary /app/tool-web