Skip to content

Correct docker-compose handling for containers that don't publish their superserver port #1613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export async function checkConnection(
workspaceState.update(wsKey + ":docker", withDocker);
workspaceState.update(wsKey + ":dockerService", service);
if (withDocker) {
if (!dockerPort || !dockerSuperserverPort) {
if (!dockerPort) {
const errorMessage = `Something is wrong with your docker-compose connection settings, or your service is not running.`;
handleError(errorMessage);
panel.text = `${PANEL_LABEL} $(error)`;
Expand All @@ -394,7 +394,7 @@ export async function checkConnection(
workspaceState.update(wsKey + ":host", "localhost");
workspaceState.update(wsKey + ":port", dockerPort);
}
if (dockerSuperserverPort !== superserverPort) {
if (dockerSuperserverPort && dockerSuperserverPort !== superserverPort) {
workspaceState.update(wsKey + ":superserverPort", dockerSuperserverPort);
}
connInfo = `localhost:${dockerPort}[${ns}]`;
Expand Down
6 changes: 5 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ async function composeCommand(cwd?: string): Promise<string> {

export async function portFromDockerCompose(
workspaceFolderName?: string
): Promise<{ port: number; superserverPort: number; docker: boolean; service?: string }> {
): Promise<{ port: number | null; superserverPort: number | null; docker: boolean; service?: string }> {
// When running remotely, behave as if there is no docker-compose object within objectscript.conn
if (extensionContext.extension.extensionKind === vscode.ExtensionKind.Workspace) {
return { docker: false, port: null, superserverPort: null };
Expand Down Expand Up @@ -512,6 +512,10 @@ export async function portFromDockerCompose(

exec(`${cmd} port --protocol=tcp ${service} ${internalSuperserverPort}`, { cwd }, (error, stdout) => {
if (error) {
// Not an error if we were merely looking for the default port and the container doesn't publish it
if (!dockerCompose.internalSuperserverPort) {
resolve(result);
}
reject(error.message);
}
const [, superserverPort] = stdout.match(/:(\d+)/) || [];
Expand Down