如何使用 JavaScript 获取 Docker 容器的名称?
How to get the name of a Docker container using JavaScript?
我希望有人能够帮助我。我正在使用 Dockerode 通过 JavaScript 对我的 Docker 容器进行操作。
我很难获得单个容器的名称。请求是 "get the name of the container who has the id XXX",但我无法让它工作。
为此,我使用了 listContainers
并尝试使用以下选项:
docker.listContainers({id: idContainer}, Meteor.bindEnvironment(function(err, containers) {
if (containers != null) {
containers.forEach(Meteor.bindEnvironment(function(containerInfo) {
if(containerInfo.Names[0].startsWith("/")){
containerInfo.Names[0] = containerInfo.Names[0].substr(1);
console.log( containerInfo.Names[0]);
}
}));
}
}));
其中 idContainer 是已知容器的 ID
但输出包含所有容器的名称。
我真的希望有人能帮助我
查看 Docker API docs,我的看法是您的调用参数可能格式不正确。
而不是:
docker.listContainers({ id: idContainer }, function (...) {...});
您需要指定:
docker.listContainers({ filters: { id: idContainer } }, function (...) {...});
在文档中,id 参数在过滤器参数组中。
我希望有人能够帮助我。我正在使用 Dockerode 通过 JavaScript 对我的 Docker 容器进行操作。
我很难获得单个容器的名称。请求是 "get the name of the container who has the id XXX",但我无法让它工作。
为此,我使用了 listContainers
并尝试使用以下选项:
docker.listContainers({id: idContainer}, Meteor.bindEnvironment(function(err, containers) {
if (containers != null) {
containers.forEach(Meteor.bindEnvironment(function(containerInfo) {
if(containerInfo.Names[0].startsWith("/")){
containerInfo.Names[0] = containerInfo.Names[0].substr(1);
console.log( containerInfo.Names[0]);
}
}));
}
}));
其中 idContainer 是已知容器的 ID
但输出包含所有容器的名称。
我真的希望有人能帮助我
查看 Docker API docs,我的看法是您的调用参数可能格式不正确。
而不是:
docker.listContainers({ id: idContainer }, function (...) {...});
您需要指定:
docker.listContainers({ filters: { id: idContainer } }, function (...) {...});
在文档中,id 参数在过滤器参数组中。