Reputation: 59
I learn React and try to run an app. When I start the app in terminal, it goes nice and works as expected, but when I do the very same thing in container it fails. Here are the details:
root@b8457ff69aac:/app# node -v
v16.17.0
root@b8457ff69aac:/app# npm -v
8.15.0
The error:
root@b8457ff69aac:/app# npm start server
> [email protected] start
> npm run server
> [email protected] server
> live-server public --host=localhost --port=9001 --middleware=./disable-browser-cache.js
(node:134) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Serving "public" at http://localhost:9001 (http://127.0.0.1:9001)
/app/node_modules/opn/index.js:82
reject(new Error('Exited with code ' + code));
^
Error: Exited with code 3
at ChildProcess.<anonymous> (/app/node_modules/opn/index.js:82:13)
at Object.onceWrapper (node:events:628:26)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1093:16)
at Socket.<anonymous> (node:internal/child_process:451:11)
at Socket.emit (node:events:513:28)
at Pipe.<anonymous> (node:net:757:14)
Dockerfile
FROM node:16.17.0
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 9001
# for sake of debug
CMD [ "sleep" , "infinity" ]
And running it:
docker run -p 9001:9001 vote-app:test2
Upvotes: 0
Views: 397
Reputation: 169338
/app/node_modules/opn/index.js:82
reject(new Error('Exited with code ' + code));
hints that the opn
module is failing. That module is used to op(e)n a browser, which can't happen in a container.
Add --no-browser
to your live-server
command line to prevent it trying to open a browser.
Furthermore, you'll need --host=0.0.0.0
instead of --host=localhost
so the exposed port can work from within the container.
As an aside, you'll probably also want to see if you can update your version of live-server
to get rid of that deprecation warning.
Upvotes: 3