【问题标题】:ERROR: Service 'api-gateway' failed to build: ADD failed: stat /var/lib/docker/tmp/docker-builder931060141/api-gateway: no such file or directory错误:服务“api-gateway”构建失败:添加失败:stat /var/lib/docker/tmp/docker-builder931060141/api-gateway:没有这样的文件或目录
【发布时间】:2019-09-06 10:02:57
【问题描述】:

我在构建基于 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 引擎版本为:

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”构建失败:添加失败:stat /var/lib/docker/tmp/docker-builder931060141/api-gateway:没有这样的文件或目录

【问题讨论】:

  • 首先你写ADD resource/...,然后你写VOLUME /resource/你确定是同一个路径吗?一条路径以/ 开头,另一条则没有。
  • 我只是下载了github项目,没有改变任何东西“ADD api-gateway /api-gateway”是错误句。
  • 请使用代码块格式化您的问题,因为这样更易读。

标签: docker docker-compose dockerfile


【解决方案1】:

当你运行docker build时,你给它的目录就变成了上下文目录;您只能引用该目录树中的文件路径,并且COPYADD 语句中的任何文件路径始终相对于该目录。这意味着,如果您从包含 Dockerfile 的名为 api-gateway 的目录中运行 docker build. 是同一个目录。您的 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/...: no such file or directory”错误,您应该始终将长数字后面的路径组件解释为相对于您传递给docker build的目录。

【讨论】:

  • 我正在向图像添加一个目录。不仅仅是一个文件或多个文件。
猜你喜欢
  • 2019-08-30
  • 2019-02-27
  • 2020-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-16
  • 1970-01-01
相关资源
最近更新 更多