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' });
  }
}