main-site/pages/api/containers.tsx

18 lines
482 B
TypeScript
Raw Normal View History

import Docker from 'dockerode'
export default async function ContainersAPI(req: any, res: any) {
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 })
res.status(200).json(list);
}
catch (error) {
console.log(error);
res.status(500).json({ error: 'Error reading data' });
}
}