我很难让一个简单的节点应用程序在使用 vagrant 托管的 docker 容器中运行。
本页解释了基本方法:https ://www.vagrantup.com/blog/feature-preview-vagrant-1-6-docker-dev-environments.html
我无法做的是从我的机器访问节点应用程序 - 理论上我相信我应该能够看到我的“hello world”风格的节点/快速应用程序localhost:8181
......
以下是我到目前为止的内容:
流浪文件:
Vagrant.configure("2") do |config|
config.vm.provider "docker" do |d|
d.build_dir = "."
d.ports = ["8080:5000"]
# Is this necessary if EXPOSE is used in Dockerfile?
d.expose = ["5000"]
d.remains_running = true
d.volumes = ["/shared"]
end
config.vm.network "forwarded_port", guest: 8080, host: 8181
config.vm.synced_folder "~/Documents/shared", "/shared"
end
Dockerfile:
# DOCKER-VERSION 0.8.0
FROM centos:6.4
RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
RUN yum install -y npm ImageMagick
ADD . /app
# Not necessary because node_modules are bundled
# RUN cd /app; npm install
EXPOSE 5000
CMD ["node", "/app/index.js"]
我已经尽可能地遵循文档,但似乎无法实现我所追求的。有任何想法吗?
注意:节点应用程序在正常运行时工作,即$ node index
在localhost:5000
提前致谢
编辑:
index.js:
var express = require('express'),
http = require('http');
var app = express();
var port = 5000;
app.get('/', function(req, res) {
res.send('Hello World');
});
var server = http.createServer(app);
server.on('listening', function() {
console.log('Express server listening on port ' + port);
});
server.listen(port, '0.0.0.0');
setInterval(function(){
console.log('running');
}, 5000);
包.json:
{
"name": "vagrant-docker-node",
"version": "0.0.0",
"dependencies": {
"express": "^4.1.0"
},
"main": "index.js"
}