我正在尝试构建我的 Nuxt3 应用程序的 docker 映像。在为我的本地平台(macOS)构建时,这工作得很好,但是当我使用
--platform linux/amd64
构建我的 docker 映像时,它会在此步骤中无限期地挂起:
=> => # ℹ vite v4.5.0 building SSR bundle for production...
=> => # ℹ transforming...
我的 Dockerfile 创建一个新镜像,复制我的源代码,然后尝试在 docker 镜像中构建 Nuxt。同样,当省略
--platform
选项时,这没有问题。
有人知道问题可能是什么或如何调试吗?
我的完整 Dockerfile 供参考:
# originally from https://towardsserverless.com/articles/deploying-nuxt-3-ssr-webapp-with-docker
FROM node:21-alpine as build
# update and install the latest dependencies for the alpine version
RUN apk update && apk upgrade
# set work dir as app
WORKDIR /app
# copy the nuxt project package json and package json lock if available
COPY package* ./
# install all the project npm dependencies
RUN npm install
# copy all other project files to working directory
COPY . ./
# build the nuxt project to generate the artifacts in .output directory
RUN npx nuxt build
# we are using multi stage build process to keep the image size as small as possible
FROM node:21-alpine
# update and install latest dependencies, add dumb-init package
# add a non root user
RUN apk update && apk upgrade && apk add dumb-init && adduser -D nuxtuser
# set non root user
USER nuxtuser
# set work dir as app
WORKDIR /app
# copy the output directory to the /app directory from
# build stage with proper permissions for user nuxt user
COPY --chown=nuxtuser:nuxtuser --from=build /app/.output ./
# todo: find out why this step is necessary
RUN npm install sqlite3
# expose 8080 on container
EXPOSE 8080
# set app host and port . In nuxt 3 this is based on nitro and you can read
#more on this https://nitro.unjs.io/deploy/node#environment-variables
ENV HOST=0.0.0.0 PORT=8080 NODE_ENV=production
# start the app with dumb init to spawn the Node.js runtime process
# with signal support
CMD ["dumb-init","node","/app/server/index.mjs"]
我最终只需从
docker build
切换到 docker buildx build
就可以让它工作。