Docker-从子文件夹中的Dockerfile构建图像
我遇到了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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经忘记了命令
docker build -f etc/dockerfile的点。
You have forgotten the dot at the end of the command
docker build -f etc/Dockerfile .