how to use docker?

wsdo
0
wsdo
commented 3 years ago

Dockerfile

FROM node:6.10.2
ENV HOST 0.0.0.0

RUN mkdir -p /app

EXPOSE 3000

COPY . /app
WORKDIR /app
RUN npm install
RUN npm run build

CMD [ "npm", "start" ]

npm install

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected]^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm info ok
---> 1242ffb8765c
Removing intermediate container 26306d862022

npm build happen error

npm info lifecycle [email protected]1.0.0~build: Failed to exec build script
npm ERR! Linux 3.13.0-100-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v6.10.2
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected]1.0.0 build: `nuxt build && backpack build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected]1.0.0 build script 'nuxt build && backpack build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the spr package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! nuxt build && backpack build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs spr
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls spr
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /app/npm-debug.log
Removing intermediate container 2e1d415c77af
The command '/bin/sh -c npm run build' returned a non-zero code: 1
0
wushan
10
wushan
commented 3 years ago

I was struggling with docker yesterday and this is my working settings 👍 hope this helps

Dockerfile

FROM node:8.2.1

ENV NODE_ENV=production
ENV HOST 0.0.0.0

RUN mkdir -p /app
COPY . /app
WORKDIR /app
# Expose the app port
EXPOSE 3000

RUN npm install
RUN npm run build
CMD ["npm", "start"]

.dockerignore // Since you copy the whole folder, including node_modules could leading to problems.

node_modules
.nuxt
0
wsdo
0
wsdo
commented 3 years ago

i try
result
@wushan

npm install error
image
image

How do you build?

0
wushan
10
wushan
commented 3 years ago

You can basically ignore the fsevents warning but that eslint-loader isn't seems right, can you build the project without docker successfully ?

0
wsdo
0
wsdo
commented 3 years ago

my packpage.json There are "eslint-loader": "^1.6.1", Don't know why no success

{
  "name": "nuxt_base",
  "version": "1.0.0",
  "description": "Nuxt.js project",
  "author": "wangshudong <[email protected]>",
  "private": true,
  "dependencies": {
    "nuxt": "latest"
  },
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate",
    "lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
    "precommit": "npm run lint"
  },
  "devDependencies": {
    "babel-eslint": "^7.1.1",
    "eslint": "^3.15.0",
    "eslint-config-standard": "^6.2.1",
    "eslint-loader": "^1.6.1",
    "eslint-plugin-html": "^2.0.0",
    "eslint-plugin-promise": "^3.4.1",
    "eslint-plugin-standard": "^2.0.1"
  }
}
0
wsdo
0
wsdo
commented 3 years ago

do you use qq or wechat? @wushan

0
wushan
10
wushan
commented 3 years ago

Try wrap your app in express for production might solve the issue, and no, I don't have qq nor wechat.express-template

0
pi0
37.3k
pi0
commented 3 years ago

@wsdo For your problem I think you are setting NODE_ENV=production (or already set by base image) just before build STEP and Eslint is always enabled on nuxt.config.js….

Simple but not best solution is changing build step to : RUN NODE_ENV=build npm install

Also as a side note, we are internally working to investigate best practices for high quality and production ready docker/swarm based Nuxt.js deployments. Stay tuned :)

4
azaars
0
azaars
commented 2 years ago

@pi0 Any news/link on the docker/swarm based Nuxt.js deployments?

0
docmattman
5
docmattman
commented 2 years ago

@pi0, I'm also interested in running Nuxt with Docker. Any update on this?

0
vadimsg
3
vadimsg
commented 2 years ago

@pi0 any update?

0
jaaacki
0
jaaacki
commented 2 years ago

@pi0 hey there, any updates?

0
fescobar
0
fescobar
commented 2 years ago

Same error for me, any update for this issue? :(

0
besnikh
0
besnikh
commented 2 years ago

After a long time of testing I finally was able to use docker with Nuxt

Dockerfile

FROM node:8.9.1

RUN mkdir -p /app
COPY . /app
WORKDIR /app

COPY package.json /app
COPY package-lock.json /app
RUN npm install

ENV NODE_ENV=production

COPY . /app
RUN npm run build

ENV HOST 0.0.0.0
EXPOSE 3000
CMD ["npm", "start"]

then I run:
sudo docker build -t <image-name> .

fater build is done:
sudo docker run -it -p 3000:3000 <image-name>

After that I was abel to successfully go to localhost port 3000 :)

I hope this helps

0
ChrisDillinger
0
ChrisDillinger
commented 2 years ago

@besnikh Your Dockerfile worked for me. My biggest misunderstanding was the usage of ENV HOST 0.0.0.0 and how that was different from just letting my server run on localhost within the container by default.

Here is another version of Dockerfile that appears to work for me:
(I'm not too sure if me not changing WORKDIR will cause trouble for me later)

FROM node:10.7

LABEL Author Chris Dillinger

COPY ./package*.json ./
RUN npm install

ENV NODE_ENV=production

COPY . .
RUN npm run build

ENV HOST 0.0.0.0
EXPOSE 3000
CMD ["npm", "start"]

My .dockerignore file looks like:

node_modules
npm-debug.log
.nuxt

I build with:
docker build -f Dockerfile -t <name>:<tag> .

I run with:
docker run -d -p 3000:3000 <name>:<tag>

0
besnikh
0
besnikh
commented 2 years ago

@ChrisDillinger Happy that it helped.

I am using the following on production server with kubernetes

FROM node:10.9.0-alpine

RUN mkdir -p /app
COPY . /app
WORKDIR /app

RUN apk update && apk upgrade && apk add git

COPY package.json /app
#RUN npm rebuild
RUN npm install

ENV NODE_ENV=production

COPY . /app
RUN npm run build

ENV HOST 0.0.0.0
EXPOSE 3000

CMD ["npm", "start"]

you can notice #RUN npm rebuild that is to be run first time after changing node version than after that you do not need to rebuild.

Cheeers

0
Nefiron
0
Nefiron
commented a year ago

Have you guys managed to run it in a local environment with hot reload from Docker?

0
Informations
QuestionUnresolved
#c1046 - Created 3 years ago