我正在尝试使用Meteor应用来启动/停止我的Docker容器。我创立了dockerode
所以我用meteor add ongoworks:dockerode
和meteor npm install dockerode
安装了它,如果我在包文件中签入了dockerode。
但是我遇到了一个问题,我觉得它很基本 我打开一个consol,然后用:
启动我的2个容器docker start 6684787338a7 (it contains a Meteor blog running on localhost:3000)
docker start 513cfc090925 (it contains MongoDB)
然后在我的电脑上启动我的Meteor app" controlContainers"在localhost:3001和我这是我的JS + HTML。
我是否错误地创建了docker对象?或者有人可以帮我弄清楚我做错了什么?因为当我开始或停止时没有任何事情发生我可以做docker ps -a
并且仍然有我的2个容器..
import { Template } from 'meteor/templating';
import './controlPanel.html';
Template.controlPanel.onCreated(function controlPanelOnCreated() {
console.log("controlPanel is ready to work for you Mister Wayne");
Docker = require('dockerode');
/* create Docker object */
docker = new Docker({host: 'http://127.0.0.1', port: 3000});
/* create 2 var that are my containers running in docker */
meteorCtn = docker.getContainer('6684787338a7');
mongoCtn = docker.getContainer('513cfc090925');
/* I don't really understand but it's on the Dockerode page */
meteorCtn.defaultOptions.start.Binds = ["/tmp:/tmp:rw"];
mongoCtn.defaultOptions.start.Binds = ["/tmp:/tmp:rw"];
});
Template.controlPanel.events({
'click #stopAll'(event){
/* Display object containers */
console.log("docker:"); console.log(docker);
console.log("meteorCtn:"); console.log(meteorCtn);
/* list all container and show the length */
docker.listContainers(function (err, containers) {
/* containers.forEach(function (containerInfo) {
docker.getContainer(containerInfo.Id).stop(cb);
}); */
console.log("containers: " + containers.length);
console.log("err: " + err);
});
},
});

<template name="controlPanel">
<p>Start, stop and pause containers from this website</p>
<input type="button" id="stopAll" value="Stop all containers">
</template>
&#13;
答案 0 :(得分:0)
因此,如果有人正在研究它或者像我一样有问题解决方案是:
确保Dockerode代码在SERVER SIDE上运行! (这是我的错误)
您需要装载卷
volumes:
- /var/run/docker.sock:/var/run/docker.sock
然后,当您创建docker对象时,您可以执行:docker = new Docker({socketPath: '/var/run/docker.sock'});