feat(services): Add Docker port mapping sync and reconfigure workflow for local services
This commit is contained in:
@@ -215,7 +215,7 @@ export class DockerContainer {
|
||||
*/
|
||||
public async inspect(containerName: string): Promise<any> {
|
||||
try {
|
||||
const result = await this.smartshell.exec(`docker inspect ${containerName}`);
|
||||
const result = await this.smartshell.exec(`docker inspect ${containerName} 2>/dev/null`);
|
||||
if (result.exitCode === 0) {
|
||||
return JSON.parse(result.stdout);
|
||||
}
|
||||
@@ -224,4 +224,38 @@ export class DockerContainer {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get port mappings for a container
|
||||
*/
|
||||
public async getPortMappings(containerName: string): Promise<{ [key: string]: string } | null> {
|
||||
try {
|
||||
// Use docker inspect without format to get full JSON, then extract PortBindings
|
||||
const result = await this.smartshell.exec(`docker inspect ${containerName} 2>/dev/null`);
|
||||
|
||||
if (result.exitCode === 0 && result.stdout) {
|
||||
const inspectData = JSON.parse(result.stdout);
|
||||
if (inspectData && inspectData[0] && inspectData[0].HostConfig && inspectData[0].HostConfig.PortBindings) {
|
||||
const portBindings = inspectData[0].HostConfig.PortBindings;
|
||||
const mappings: { [key: string]: string } = {};
|
||||
|
||||
// Convert Docker's port binding format to simple host:container mapping
|
||||
for (const [containerPort, hostBindings] of Object.entries(portBindings)) {
|
||||
if (Array.isArray(hostBindings) && hostBindings.length > 0) {
|
||||
const hostPort = (hostBindings[0] as any).HostPort;
|
||||
if (hostPort) {
|
||||
mappings[containerPort.replace('/tcp', '').replace('/udp', '')] = hostPort;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mappings;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
// Silently fail - container might not exist
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user