Nuxt.js: Question: Dockerfile in Nuxt copying .nuxt only

Created on 21 Feb 2018  路  4Comments  路  Source: nuxt/nuxt.js

FROM node:alpine

RUN mkdir app

WORKDIR /app

COPY package.json .

RUN npm i

COPY .nuxt ./.nuxt

CMD ["npm", "run", "start"]

this is what i have in my docker file but it seems i've gotten some errors about < JSON unexpected

any ideas?

This question is available on Nuxt.js community (#c2494)
help-wanted

Most helpful comment

You can use multi-stage builds.

This is my dockerfile for most of my Nuxt Projects :

FROM node:9.5-alpine as builder
WORKDIR /app
ENV NODE_ENV=production
RUN  apk add --no-cache curl git && cd /tmp && \
  curl -#L https://github.com/tj/node-prune/releases/download/v1.0.1/node-prune_1.0.1_linux_amd64.tar.gz | tar -xvzf- && \
  mv -v node-prune /usr/local/bin && rm -rvf * && \
  echo "yarn cache clean && node-prune" > /usr/local/bin/node-clean && chmod +x /usr/local/bin/node-clean
ADD package.json yarn.lock ./
RUN yarn --frozen-lockfile --non-interactive && node-clean

ADD . ./
RUN yarn build

FROM node:9.5-alpine
WORKDIR /app
ENV NODE_ENV=production
ADD package.json ./
ADD nuxt.config.js ./
COPY --from=builder ./app/node_modules ./node_modules/
COPY --from=builder ./app/.nuxt ./.nuxt/
COPY --from=builder ./app/static ./static/
EXPOSE 3333
CMD ["yarn", "start"]

All 4 comments

Not sure about the error you're receiving, but I recommend running a Nuxt build within the container rather than copying the build output.

FROM node:carbon

# Set environment variables
ENV NODE_ENV=production
# otherwise the app is unavailable to the host running Docker
ENV HOST=0.0.0.0

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install --only=production

# Bundle app source
COPY . .

# Build Nuxt app
RUN npm run build

# Expose the app's port
EXPOSE 3000

CMD [ "npm", "run", "start" ]

Then just make sure you also have a .dockerignore file with at least the following content:

npm-debug.log
.nuxt

If you still want to debug your problem, please include the exact commands you ran to get the error and copy-paste the full output of those commands including the error you received.

You can use multi-stage builds.

This is my dockerfile for most of my Nuxt Projects :

FROM node:9.5-alpine as builder
WORKDIR /app
ENV NODE_ENV=production
RUN  apk add --no-cache curl git && cd /tmp && \
  curl -#L https://github.com/tj/node-prune/releases/download/v1.0.1/node-prune_1.0.1_linux_amd64.tar.gz | tar -xvzf- && \
  mv -v node-prune /usr/local/bin && rm -rvf * && \
  echo "yarn cache clean && node-prune" > /usr/local/bin/node-clean && chmod +x /usr/local/bin/node-clean
ADD package.json yarn.lock ./
RUN yarn --frozen-lockfile --non-interactive && node-clean

ADD . ./
RUN yarn build

FROM node:9.5-alpine
WORKDIR /app
ENV NODE_ENV=production
ADD package.json ./
ADD nuxt.config.js ./
COPY --from=builder ./app/node_modules ./node_modules/
COPY --from=builder ./app/.nuxt ./.nuxt/
COPY --from=builder ./app/static ./static/
EXPOSE 3333
CMD ["yarn", "start"]

Not working with analyzer port.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bimohxh picture bimohxh  路  3Comments

gary149 picture gary149  路  3Comments

vadimsg picture vadimsg  路  3Comments

mikekidder picture mikekidder  路  3Comments

lazycrazy picture lazycrazy  路  3Comments