skip to Main Content

I am trying to build a docker image of my Nuxt3 app. This works fine when building for my local platform (macOS), but when I build my docker image with --platform linux/amd64, it hangs indefinitely in this step:

 => => # ℹ vite v4.5.0 building SSR bundle for production...
 => => # ℹ transforming...

My Dockerfile creates a new image, copies my sources over and then tries to build Nuxt inside the docker image. Again, when omitting the --platform option, this works with no issues.

Does anybody know what the issue might be or how to debug this?

My full Dockerfile for reference:

# 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"]

2

Answers


  1. Chosen as BEST ANSWER

    I eventually managed to get this to work simply by switching from docker build to docker buildx build.


  2. I ran into the same issue, M1 MacOS 14 Sonoma and specifying –platform=x86_64. Using Docker Desktop version v4.25.1 as well.

    What worked for me was disabling the "Use Rosetta for x86/amd64 emulation on Apple Silicon" option in Docker settings. After restarting the same build was able to successfully pass the transform stage.

    Credit here where I found this: https://www.reddit.com/r/node/comments/11ylxvu/comment/k3knkgs/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search