我试图为我的盖茨比应用程序构建Docker映像。每当我运行命令docker构建。-t gatsbyapp,它会给出一个错误:

failed to solve with frontend dockerfile.v0: failed to build LLB:
failed to compute cache key: "/.env" not found: not found

同时我的Dockerfile如下所示:

FROM node:13

WORKDIR /app

COPY package.json .

RUN yarn global add gatsby-cli

RUN yarn install

COPY gatsby-config.js .

COPY .env .

EXPOSE 8000

CMD ["gatsby","develop","-H","0.0.0.0"]

当前回答

对我来说

我打开Docker桌面->打开设置->Docker引擎->

{
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": false,
  "features": {
    "buildkit": false
  }
}

这里我的buildkit的默认值是true ->我更改为false并重新启动docker引擎

这对我很有用

其他回答

我犯了同样的错误,但是把Dockerfile从子文件夹移到应用程序的根文件夹中。它修复了错误消息。

通过设置HTTP_PROYY和HTTP_PROXYS环境变量来指定代理服务器。

例子:

http_proxy=http://username:password@proxy.example.com:8080
https_proxy=http://username:password@proxy.example.com:8080

对我来说

我打开Docker桌面->打开设置->Docker引擎->

{
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": false,
  "features": {
    "buildkit": false
  }
}

这里我的buildkit的默认值是true ->我更改为false并重新启动docker引擎

这对我很有用

我所需要做的只是在构建中添加—no-cache作为参数。

如果你在Mac或Windows上使用Docker Desktop,你可能也必须在你的“Docker引擎”JSON配置中禁用它。

Docker Desktop→Settings→Docker Engine→将“features”:{buildkit: true}改为“features”:{buildkit: false}。