错误:服务'api-gateway'无法构建:ADD失败:stat / var / lib / docker / tmp / docker-builder931060141 / api-gateway:没有这样的文件或目录

问题描述 投票:0回答:1

我在构建基于Go的Docker项目时遇到了麻烦。我的整体目录结构如下:

api-gateway
│  ├─handler
│  └─resource
   --Dockerfile

我的Dockerfile包含:

FROM alpine:3.2
ADD api-gateway /api-gateway
ADD resource/pri_key.pem resource/pub_key.pem /resource/
#ADD resource/ca-certificates.crt /etc/ssl/certs/
VOLUME /resource/
ENTRYPOINT [ "/api-gateway" ]

即使我使用ADD在图像中包含文件,我仍然会收到错误。 api-gateway是一个目录,其中包括Dockerfile

D:\FileWithDocument\ExtraCodeProject\shop-micro-master>docker-compose up
Building api-gateway
Step 1/5 : FROM alpine:3.2
 ---> 98f5f2d17bd1
Step 2/5 : ADD api-gateway /api-gateway
ERROR: Service 'api-gateway' failed to build: ADD failed: stat /var/lib/docker/tmp/docker-builder931060141/api-gateway: no such file or directory

我在Windows中使用Docker Desktop。 Docker Engine版本是:

Client: Docker Engine - Community
 Version:           18.09.2
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        6247962
 Built:             Sun Feb 10 04:12:31 2019
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       6247962
  Built:            Sun Feb 10 04:13:06 2019
  OS/Arch:          linux/amd64
  Experimental:     true

当我下载github项目并运行docker build时,它仍会输出此错误。

错误:服务'api-gateway'无法构建:ADD失败:stat / var / lib / docker / tmp / docker-builder931060141 / api-gateway:没有这样的文件或目录

docker docker-compose dockerfile
1个回答
0
投票

运行docker build时,您提供的目录将成为上下文目录;您只能引用该目录树中的文件路径,COPYADD语句中的任何文件路径始终相对于该目录。这意味着如果您从包含docker build的名为api-gateway的目录运行Dockerfile,则.是同一目录。您的Dockerfile可能看起来更像:

FROM alpine:3.2

# This will create the directory in the image if it
# doesn't already exist.
WORKDIR /api-gateway

# Copy the entire current directory into the image.
# (Prefer COPY to ADD, unless you specifically want
# automatic archive extraction or HTTP fetches.)
COPY . .

# Copy in some additional files.
# (Remember that anyone who has the image can extract any
# file from it: this leaks a private key.)
COPY resource/pri_key.pem resource/pub_key.pem /resource/
COPY resource/ca-certificates.crt /etc/ssl/certs/

# Set the default command to launch.
# (Prefer CMD to ENTRYPOINT: it is easier to get a debugging
# container with a shell, and there is a useful pattern that
# uses an ENTRYPOINT wrapper to do first-time setup before
# launching the CMD.)
CMD ["/api-gateway/handler"]

如果您看到“docker-builder12345678 / ...:没有此类文件或目录”错误,则应始终将长号后面的路径组件解释为相对于传递给docker build的目录。

© www.soinside.com 2019 - 2024. All rights reserved.