skip to Main Content

I build my Nuxt3 Applcation with this command which generates everything in a Folder .output:

npm run build

This is the DockerFile that I’m using to build the docker file:

FROM node:17-alpine3.14

ADD .output /webapp/.output

EXPOSE 3000

WORKDIR /webapp/.output

ENTRYPOINT ["node", "/webapp/.output/server/index.mjs"]

and docker-compose.yml looks like this:

version: '3.3'

services:
  app-web:
    build: .
    ports:
      - 3000:3000

everything runs without any errors but I expected to see the application by entering the address http://localhost:3000 but nothing happens.

Any Help is highly appreciated.

4

Answers


  1. Chosen as BEST ANSWER

    here is the working version:

    FROM node:17-alpine3.14
    
    ADD .output /webapp/.output
    
    EXPOSE 3000
    
    WORKDIR /webapp/.output
    
    ENV NUXT_HOST=0.0.0.0
    ENV NUXT_PORT=3000
    
    CMD ["node", "/webapp/.output/server/index.mjs"]
    

  2. My approach:

    Docker Compose (for development)

    version: '3'
    services:
    
      web-app:
        image: node:17-alpine
        container_name: web-app
        command: [sh, -c, "npm i && npm run dev"]
        ports:
          - "3000:3000"
        working_dir: '/webapp'
        tty: true
        volumes:
          - './:/webapp/'
        environment:
          HOST: 0.0.0.0
          PORT: 3000
    

    Docker (production)

    FROM node:17-alpine
    
    ENV HOST='0.0.0.0'
    ENV PORT='3000'
    
    WORKDIR /webapp
    
    COPY ./ /webapp
    
    RUN npm install
    RUN npm run build
    
    EXPOSE 3000
    
    CMD [ "npm", "run", "start" ]
    
    Login or Signup to reply.
  3. This is the Dockerfile we use to run our nuxt3 setup!

    # see https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
    ARG NODE_VERSION=node:16.14.2
    
    FROM $NODE_VERSION AS dependency-base
    
    # create destination directory
    RUN mkdir -p /app
    WORKDIR /app
    
    # copy the app, note .dockerignore
    COPY package.json .
    COPY package-lock.json .
    RUN npm ci
    
    FROM dependency-base AS production-base
    
    # build will also take care of building
    # if necessary
    COPY . .
    RUN npm run build
    
    FROM $NODE_VERSION-slim AS production
    
    COPY --from=production-base /app/.output /app/.output
    
    # Service hostname
    ENV NUXT_HOST=0.0.0.0
    
    # Service version
    ARG NUXT_APP_VERSION
    ENV NUXT_APP_VERSION=${NUXT_APP_VERSION}
    
    # Run in production mode
    ENV NODE_ENV=production
    
    # start the app
    CMD [ "node", "/app/.output/server/index.mjs" ]
    

    You can find an example here: https://github.com/sidestream-tech/sidebase/blob/main/Dockerfile

    Login or Signup to reply.
  4. This is the Dockerfile I have created.

    Github Gist

    FROM node:lts-alpine
    
    WORKDIR /app
    
    COPY package*.json ./
    
    RUN npm ci
    
    COPY . .
    
    RUN npm run build
    
    # customize port 80
    EXPOSE 80
    CMD ["sh", "-c", "NITRO_PORT=80 node .output/server/index.mjs"]
    
    # default port 3000
    # EXPOSE 3000
    # CMD ["node", ".output/server/index.mjs"]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search