Docker-从子文件夹中的Dockerfile构建图像

发布于 2025-02-06 11:06:08 字数 1377 浏览 0 评论 0原文

我遇到了Docker遇到的问题,即无法通过查看其他参考,文档等解决问题。而且,由于我是Docker的初学者,因此我在这里尝试运气。我正在使用使用Docker构建应用程序的Next.js项目。我正在使用示例文档 next.js和,如果我将dockerfile放在项目的根源中,有效。但是,我想将其放入一个名为etc的文件夹中,然后从那里使用它。这给了我问题,因为Docker找不到要复制到工作目录的文件,请参见下面的错误。

结构

.
├── etc
│   └── Dockerfile
├── package.json
└── yarn.lock

命令

docker build etc/

错误

无法计算缓存键:“/YARN.LOCK”找不到:找不到

dockerfile

FROM node:16-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

我尝试了很多事情,例如更改文件和路径。另外,在文档 ,但这对我不起作用,因为我得到错误“ Docker build”需要1个参数。运行docker build -f etc/dockerfile。这过时了吗?无论如何,我的问题是,当我的dockerfile不在项目的根上,而是在子文件夹中,例如etc/,如何使用Docker构建我的应用程序。

I'm running into a problem with docker that I can't fix by looking at other references, documentation, etc. and since i'm a beginner with Docker I try my luck here. I'm working in a Next.js project that is using Docker to build the app. I'm using the example documentation of Next.js, and that works if I have my Dockerfile in the root of my project. However, I want to put it in a folder called etc and use it from there. This is giving me problems, because docker can't find the files that i'm trying to copy to the working directory, see error below.

Structure

.
├── etc
│   └── Dockerfile
├── package.json
└── yarn.lock

Command

docker build etc/

Error

failed to compute cache key: "/yarn.lock" not found: not found

Dockerfile

FROM node:16-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

I've tried a bunch of things, such as changing the files and paths. Also, in the documentation they mention the -f flag, but that doesn't work for me either because I get the error "docker build" requires exactly 1 argument. when running docker build -f etc/Dockerfile. Is that outdated? Anyway, my question is how to build my app with docker when my dockerfile is not in the root of the project but in a child folder like etc/.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本宫微胖 2025-02-13 11:06:10

您已经忘记了命令docker build -f etc/dockerfile的点。

You have forgotten the dot at the end of the command docker build -f etc/Dockerfile .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文