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 /registry./build-image/debian-base:bullseye-v1.4.3 0.0s
=> [1/4] FROM /registry./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
#
# /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 /registry./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
#
# /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 /registry./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