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?
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.
Most helpful comment
You can use multi-stage builds.
This is my dockerfile for most of my Nuxt Projects :