This commit is contained in:
Raven Scott 2024-11-29 18:27:37 -05:00
parent 7c19fe58a6
commit d54328c001

View File

@ -60,13 +60,16 @@ swarm.on('connection', (peer) => {
console.log('[INFO] Handling \'listContainers\' command');
const containers = await docker.listContainers({ all: true });
// Fetch detailed network info for each container
const detailedContainers = await Promise.all(
containers.map(async (container) => {
const details = await docker.getContainer(container.Id).inspect();
console.log(details.NetworkSettings.Networks); // Log the network details
// Safely access the IP address
const ipAddress = details.NetworkSettings.Networks
? Object.values(details.NetworkSettings.Networks)[0].IPAddress
: '-';
? Object.values(details.NetworkSettings.Networks)[0]?.IPAddress || 'No IP Assigned'
: 'No Networks';
return { ...container, ipAddress }; // Add IP address to container data
})
);