0

这是我的 Dockerfile 代码:

FROM node:16.10-alpine3.12 as base
RUN apk update
RUN apk add git
WORKDIR /app
COPY package.json .

FROM base as builder
RUN npm i
COPY . .
RUN npm run build

FROM base as prod
WORKDIR /exfront
COPY --from=builder /app/package.json .
RUN npm i
COPY --from=builder /app/.nuxt .nuxt
COPY --from=builder /app/static static
COPY --from=builder /app/nuxt.config.js .
EXPOSE 3500
ENV NUXT_HOST=0.0.0.0
ENV NUXT_PORT=3500
CMD ["npm","start"]

而且我的 .dockerignore 文件包含这些:

.dockerignore
node_modules
npm-debug.*
Dockerfile
.git
.gitignore

我在(第 8 步复制 ..)中收到此错误

Error processing tar file(duplicates of file paths not supported):

码头工人错误

另一个问题是我必须安装 git,所以有两个命令:apk update && apk add git

因为如果我不在 npm 安装中,我会收到 git error Idk 为什么会发生这种情况,如果无论如何我可以删除这个命令,那就更好了

4

1 回答 1

1

我在我这边尝试了这个 Dockerfile,它工作正常:我看到你做了一些未使用的步骤,比如将代码从基础复制到生成器,然后再到 prod,在这种情况下,你在没有优化图像层的情况下转身。你可以使用下面的 Dockerfile 来构建你的 Nuxt 镜像:

# Dockerfile
FROM node:16.10-alpine3.12 as base

# create destination directory
RUN mkdir -p /usr/src/nuxt-app
WORKDIR /usr/src/nuxt-app

# update and install dependency
RUN apk update && apk upgrade
RUN apk add git

# copy the app, note .dockerignore
COPY . /usr/src/nuxt-app/
RUN npm install
RUN npm run build


ENV NUXT_HOST=0.0.0.0
ENV NUXT_PORT=3000
EXPOSE 3000

CMD [ "npm", "start" ]

要构建使用此命令:

docker build -t nuxt-app:v0.1 .
于 2022-02-14T10:11:46.867 回答