我试图为我的盖茨比应用程序构建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"]

当前回答

在我的情况下,我不得不卸载Astrill VPN。

其他回答

确保你使用相同的平台,例如: 如果使用。构建第一个映像(my-custom-service)

FROM --platform=linux/amd64 node:14

然后你需要将——platform添加到其他使用第一个基映像的dockerfile中:

FROM --platform=linux/amd64 my-custom-service

如果你之前执行了docker buildx install,你的docker命令别名为docker buildx,它基于docker Buildkit,目前不支持(遗憾的是)Windows容器。

使用实例删除别名。

docker buildx uninstall

我希望这能为像我这样忘记这个别名的人节省时间

就我而言,我有两个问题:

我错过了。在给出上下文选项的命令的末尾,和 我在Dockerfile的文件名中有一个“。txt”扩展名。

经过这两次调整,一切都达到了预期的效果。

如果你在Windows中使用Docker,你需要在设置中禁用Docker引擎中的buildkit。它适用于我,解决了我的错误

将buildkit选项设置为false。

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

在我的例子中,我在context选项中的"."后面有一个额外的空格:

docker build -t myapp .[EXTRA_SPACE_HERE]