This commit is contained in:
Raven Scott 2024-11-29 18:23:27 -05:00
parent b9e8c6da2f
commit 7c19fe58a6
2 changed files with 33 additions and 24 deletions

43
app.js
View File

@ -299,9 +299,11 @@ function renderContainers(containers) {
containerList.innerHTML = ''; // Clear the current list
containers.forEach((container) => {
const name = container.Names[0].replace(/^\//, ''); // Remove leading slash from container names
const name = container.Names[0].replace(/^\//, ''); // Remove leading slash
const image = container.Image;
const containerId = container.Id;
const ipAddress = container.ipAddress || '-'; // Use the IP address field
const row = document.createElement('tr');
row.dataset.containerId = containerId; // Store container ID for reference
row.innerHTML = `
@ -310,37 +312,32 @@ function renderContainers(containers) {
<td>${container.State}</td>
<td class="cpu">0</td>
<td class="memory">0</td>
<td class="ip-address">-</td>
<td class="ip-address">${ipAddress}</td>
<td>
<button class="btn btn-success btn-sm action-start" ${container.State === 'running' ? 'disabled' : ''}>
<i class="fas fa-play"></i>
</button>
<button class="btn btn-warning btn-sm action-stop" ${container.State !== 'running' ? 'disabled' : ''}>
<i class="fas fa-stop"></i>
</button>
<button class="btn btn-danger btn-sm action-remove">
<i class="fas fa-trash"></i>
</button>
<button class="btn btn-primary btn-sm action-terminal" ${container.State !== 'running' ? 'disabled' : ''}>
<i class="fas fa-terminal"></i>
</button>
<button class="btn btn-secondary btn-sm action-duplicate">
<i class="fas fa-clone"></i>
</button>
<button class="btn btn-success btn-sm action-start" ${container.State === 'running' ? 'disabled' : ''}>
<i class="fas fa-play"></i>
</button>
<button class="btn btn-warning btn-sm action-stop" ${container.State !== 'running' ? 'disabled' : ''}>
<i class="fas fa-stop"></i>
</button>
<button class="btn btn-danger btn-sm action-remove">
<i class="fas fa-trash"></i>
</button>
<button class="btn btn-primary btn-sm action-terminal" ${container.State !== 'running' ? 'disabled' : ''}>
<i class="fas fa-terminal"></i>
</button>
<button class="btn btn-secondary btn-sm action-duplicate">
<i class="fas fa-clone"></i>
</button>
</td>
`;
`;
containerList.appendChild(row);
// Add event listeners for action buttons
addActionListeners(row, container);
// Add event listener for duplicate button
const duplicateBtn = row.querySelector('.action-duplicate');
duplicateBtn.addEventListener('click', () => openDuplicateModal(container));
});
}
// Add event listeners to action buttons
function addActionListeners(row, container) {
const startBtn = row.querySelector('.action-start');

View File

@ -59,7 +59,19 @@ swarm.on('connection', (peer) => {
case 'listContainers':
console.log('[INFO] Handling \'listContainers\' command');
const containers = await docker.listContainers({ all: true });
response = { type: 'containers', data: containers };
// Fetch detailed network info for each container
const detailedContainers = await Promise.all(
containers.map(async (container) => {
const details = await docker.getContainer(container.Id).inspect();
const ipAddress = details.NetworkSettings.Networks
? Object.values(details.NetworkSettings.Networks)[0].IPAddress
: '-';
return { ...container, ipAddress }; // Add IP address to container data
})
);
response = { type: 'containers', data: detailedContainers };
break;
case 'inspectContainer':