Switched over to using Docker API
ToDo: Change location to actual location
This commit is contained in:
parent
c77fc44172
commit
a1bf08ddce
4 changed files with 36 additions and 11 deletions
pages/api
|
@ -1,13 +1,27 @@
|
|||
import Docker from 'dockerode'
|
||||
import ApiSecret from '../../private/portainer_api_secret.json'
|
||||
import { DockerInfo } from '../../interfaces/DockerStatus';
|
||||
|
||||
export default async function ContainersAPI(req: any, res: any) {
|
||||
const token = JSON.parse(JSON.stringify(ApiSecret.token));
|
||||
|
||||
try {
|
||||
const options = {
|
||||
socketPath: '/var/run/docker.sock',
|
||||
path: '/v1.41/containers/json'
|
||||
};
|
||||
var docker = new Docker({ socketPath: options.socketPath });
|
||||
const list = await docker.listContainers({ all: true })
|
||||
const res1 = await fetch('https://portainer.neshweb.net/api/endpoints/2/docker/containers/json', {
|
||||
method: "GET",
|
||||
headers: {"X-API-Key": token}
|
||||
});
|
||||
|
||||
const unparsed = await res1.json();
|
||||
let list: DockerInfo[] = [];
|
||||
|
||||
unparsed.forEach((entry: any) => {
|
||||
let newEntry = {} as DockerInfo;
|
||||
|
||||
newEntry.name = entry.Names[0].substring(1);
|
||||
newEntry.status = entry.State;
|
||||
newEntry.id = entry.Id;
|
||||
list.push(newEntry);
|
||||
});
|
||||
|
||||
res.status(200).json(list);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue