我正试图通过跟踪本指南来修改我的Nuxt应用程序。如果输入在其中编写的命令,它就能工作,但我想使用docker-compose简化它。我还在学习码头的事。
到目前为止,我已经创建了一个docker-compose.yml文件
version: '3'
services:
nuxt-app:
container_name: nuxt-app
build:
context: .
dockerfile: Dockerfile
volumes:
- '.:/app'
- '/app/node_modules'
ports:
- '3000:3000'但是当我运行docker-compose up时,它会显示这个错误
[+] Running 2/2
⠿ Network nuxt-app_default Created 0.7s
⠿ Container nuxt-app Created 30.3s
Attaching to nuxt-app
nuxt-app | yarn run v1.22.17
nuxt-app | $ nuxt start
nuxt-app |
nuxt-app | FATAL No build files found in /app/.nuxt/dist/server.
nuxt-app | Use either `nuxt build` or `builder.build()` or start nuxt in development mode.
nuxt-app |
nuxt-app | Use either `nuxt build` or `builder.build()` or start nuxt in development mode.
nuxt-app | at VueRenderer._ready (node_modules/@nuxt/vue-renderer/dist/vue-renderer.js:758:13)
nuxt-app | at async Server.ready (node_modules/@nuxt/server/dist/server.js:637:5)
nuxt-app | at async Nuxt._init (node_modules/@nuxt/core/dist/core.js:482:7)
nuxt-app |
nuxt-app |
nuxt-app |
╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ ✖ Nuxt Fatal Error │
│ │
│ Error: No build files found in /app/.nuxt/dist/server. │
│ Use either `nuxt build` or `builder.build()` or start nuxt in │
│ development mode. │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯
nuxt-app |
nuxt-app | error Command failed with exit code 1.
nuxt-app | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
nuxt-app exited with code 1我的Dockerfile看起来像这样
FROM node:lts as builder
WORKDIR /app
COPY . .
RUN yarn install \
--prefer-offline \
--frozen-lockfile \
--non-interactive \
--production=false
RUN yarn build
RUN rm -rf node_modules && \
NODE_ENV=production yarn install \
--prefer-offline \
--pure-lockfile \
--non-interactive \
--production=true
FROM node:lts
WORKDIR /app
COPY --from=builder /app .
ENV HOST 0.0.0.0
EXPOSE 80
CMD [ "yarn", "start" ]有谁能告诉我为什么会发生这种事,我怎样才能让它起作用?
更新
如果我在yarn build之前做docker-compose up,这个问题似乎就解决了。
发布于 2022-03-08 11:21:17
volumes:挂载隐藏了您的Dockerfile所做的一切。在构建了应用程序并在其周围创建了一个最小的映像之后,然后挂载您的主机目录并使所有这些都不可见。这也是为什么在本地运行yarn build似乎很有帮助:它在将Dockerfile挂载到容器之前重新创建了您的Dockerfile在主机上构建的目录。
您可以将docker-compose.yml减少到
version: '3.8'
services:
nuxt-app:
build: .
ports:
- '3000:3000'不使用volumes:,也不覆盖container_name:组合本身提供的内容,并且使用更短的build:形式,因为否则您将使用默认选项。
https://stackoverflow.com/questions/71391832
复制相似问题