gpt4 book ai didi

node.js - 无法启动 Node 缺失模块

转载 作者:行者123 更新时间:2023-12-02 21:08:47 24 4
gpt4 key购买 nike

我是 Node 新手,所以以此为起点。

https://github.com/voduytuan/docker-socketio

APP.JS

var http = require('http');
var socketio = require('socket.io');

var app = http.createServer(function(req, res) {
var postData = "";
req.on('data', function(chunk) {
postData += chunk; //Get the POST data
});

req.on('end', function() {
if (typeof(postData) !== "undefined") {
var message = JSON.parse(postData);

//Do something here
//Todo...
}
});
res.end();
}).listen(8080); //Use a non-standard port so it doesn't override your Apache

var io = socketio.listen(app); //Attach socket.io to port 8080

io.sockets.on('connection', function(socket) {
socket.on('disconnect', function () {

});
});

docker 运行:
docker run -ti -d --restart=always --name mysocketio -v app.js:/srv/app.js -p 8080:8080 voduytuan/docker-socketio

docker 文件:
FROM zzrot/alpine-node
MAINTAINER Vo Duy Tuan <tuanmaster2012@gmail.com>

RUN apk add --update \
supervisor \
&& rm -rf /var/cache/apk/*

ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf

RUN /bin/mkdir -p /srv/logs

WORKDIR /srv


RUN npm install --silent socket.io@0.9.14
RUN npm dedupe

EXPOSE 8080

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

目录:

Dockerfile
执照
自述文件.md
supervisord.conf
应用程序.js

当我查看日志文件时,我看到了这个?
Error: Cannot find module '/srv/app.js'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.runMain (module.js:575:10)
at run (bootstrap_node.js:352:7)
at startup (bootstrap_node.js:144:9)
at bootstrap_node.js:467:3

最佳答案

你没有 app.js在你的 Docker 容器中。

要添加它,请修改 Dockerfile并添加 ADD命令:

FROM zzrot/alpine-node
MAINTAINER Vo Duy Tuan <tuanmaster2012@gmail.com>

RUN apk add --update \
supervisor \
&& rm -rf /var/cache/apk/*

ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf

##### CHANGE HERE:
ADD app.js /srv/
#####

RUN /bin/mkdir -p /srv/logs

WORKDIR /srv


RUN npm install --silent socket.io@0.9.14
RUN npm dedupe

EXPOSE 8080

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

关于node.js - 无法启动 Node 缺失模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56241503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com