failed to solve: failed to compute cache key: xxx not found

1. 错误日志

failed to solve: failed to compute cache key: failed to calculate checksum of ref edf7ad9c-3617-4702-a7fd-1002d7ca82f1::q90bm8nfq07ew9xhjopvo5s3k: "/root/go/bin/dlv": not found

2. 详细错误日志

[root@harbor csi-driver-nfs]# make local-build-push
/bin/cp -f /root/go/bin/dlv ./bin/amd64/
docker build --build-arg ARCH="amd64" -t 192.168.11.20/csi/nfsplugin:latest .
[+] Building 0.0s (7/8)                                                                                                                                       docker:default
 => [internal] load build definition from Dockerfile                                                                                                                    0.0s
 => => transferring dockerfile: 1.09kB                                                                                                                                  0.0s
 => [internal] load .dockerignore                                                                                                                                       0.0s
 => => transferring context: 2B                                                                                                                                         0.0s
 => [internal] load metadata for m.daocloud.io/registry.k8s.io/build-image/debian-base:bullseye-v1.4.3                                                                  0.0s
 => [1/4] FROM m.daocloud.io/registry.k8s.io/build-image/debian-base:bullseye-v1.4.3@sha256:3fcf9bcc4949392155cde1f96591ba3eda092f4735a9cc856bf526d71f48af47            0.0s
 => [internal] load build context                                                                                                                                       0.0s
 => => transferring context: 95B                                                                                                                                        0.0s
 => CACHED [2/4] COPY ./bin/amd64/nfsplugin /nfsplugin                                                                                                                  0.0s
 => ERROR [3/4] COPY /root/go/bin/dlv /usr/local/bin/dlv                                                                                                                0.0s
------
 > [3/4] COPY /root/go/bin/dlv /usr/local/bin/dlv:
------
Dockerfile:21
--------------------
  19 |     COPY ${binary} /nfsplugin
  21 | >>> COPY /root/go/bin/dlv /usr/local/bin/dlv
  22 |
  23 |     RUN apt update && apt upgrade -y && apt-mark unhold libcap2 && clean-install ca-certificates mount nfs-common netbase
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref edf7ad9c-3617-4702-a7fd-1002d7ca82f1::q90bm8nfq07ew9xhjopvo5s3k: "/root/go/bin/dlv": not found
make: *** [local-build-push] Error 1

3. 原始Dockerfile

# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM m.daocloud.io/registry.k8s.io/build-image/debian-base:bullseye-v1.4.3

ARG ARCH
ARG binary=./bin/${ARCH}/nfsplugin
COPY ${binary} /nfsplugin
COPY /root/go/bin/dlv /usr/local/bin/dlv

RUN apt update && apt upgrade -y && apt-mark unhold libcap2 && clean-install ca-certificates mount nfs-common netbase

ENTRYPOINT ["dlv --listen=:12800 --headless=true --api-version=2 --accept-multiclient exec /nfsplugin -- "]

Makefile如下

ARCH=amd64
LOCAL_USER=192.168.11.20/csi
.PHONY: local-build-push
local-build-push:
	docker build --build-arg ARCH="${ARCH}" -t $(LOCAL_USER)/nfsplugin:latest .
	docker push $(LOCAL_USER)/nfsplugin

.PHONY: nfs
nfs:
	CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -a -ldflags "${LDFLAGS}" -gcflags=all="-N -l" -mod vendor -o bin/${ARCH}/nfsplugin ./cmd/nfsplugin

4. 问题分析

  • 1、宿主机中肯定存在/root/go/bin/dlv这个二进制文件
  • 2、猜测一定是由于dockerfile构建过程导致的文件找不到问题。
  • 3、通过网上搜索,发现就是由于COPY目录的问题,改为相对路径可以解决问题

5. 修改后的dockerfile

# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM m.daocloud.io/registry.k8s.io/build-image/debian-base:bullseye-v1.4.3

ARG ARCH
ARG binary=./bin/${ARCH}/nfsplugin
COPY ${binary} /nfsplugin
COPY ./bin/${ARCH}/dlv /usr/local/bin/dlv

RUN apt update && apt upgrade -y && apt-mark unhold libcap2 && clean-install ca-certificates mount nfs-common netbase

ENTRYPOINT ["dlv --listen=:12800 --headless=true --api-version=2 --accept-multiclient exec /nfsplugin -- "]

修改后的Makefile如下

ARCH=amd64
LOCAL_USER=192.168.11.20/csi
.PHONY: local-build-push
local-build-push:
	/bin/cp -f /root/go/bin/dlv ./bin/amd64/
	docker build --build-arg ARCH="${ARCH}" -t $(LOCAL_USER)/nfsplugin:latest .
	docker push $(LOCAL_USER)/nfsplugin

.PHONY: nfs
nfs:
	CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -a -ldflags "${LDFLAGS}" -gcflags=all="-N -l" -mod vendor -o bin/${ARCH}/nfsplugin ./cmd/nfsplugin
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值