2022-12-10 20:18:55 +00:00
|
|
|
import Docker from 'dockerode'
|
2022-12-10 02:02:03 +00:00
|
|
|
|
2022-12-10 20:18:55 +00:00
|
|
|
export default async function ContainersAPI(req: any, res: any) {
|
2022-12-10 02:02:03 +00:00
|
|
|
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' });
|
|
|
|
}
|
|
|
|
}
|