diff --git a/src/commands/compose.ts b/src/commands/compose.ts index 2e907bf8ad..1b6facc2ec 100644 --- a/src/commands/compose.ts +++ b/src/commands/compose.ts @@ -46,7 +46,7 @@ async function compose(context: IActionContext, commands: ('up' | 'down')[], mes detached, build ); - terminal.sendText(terminalCommand); + terminal.sendText(await rewriteCommandForNewCliIfNeeded(terminalCommand)); } else { for (const item of selectedItems) { const terminalCommand = await selectComposeCommand( @@ -57,7 +57,7 @@ async function compose(context: IActionContext, commands: ('up' | 'down')[], mes detached, build ); - terminal.sendText(terminalCommand); + terminal.sendText(await rewriteCommandForNewCliIfNeeded(terminalCommand)); } } terminal.show(); @@ -75,3 +75,12 @@ export async function composeDown(context: IActionContext, dockerComposeFileUri? export async function composeRestart(context: IActionContext, dockerComposeFileUri?: vscode.Uri, selectedComposeFileUris?: vscode.Uri[]): Promise { return await compose(context, ['down', 'up'], localize('vscode-docker.commands.compose.chooseRestart', 'Choose Docker Compose file to restart'), dockerComposeFileUri, selectedComposeFileUris); } + +async function rewriteCommandForNewCliIfNeeded(command: string): Promise { + if ((await ext.dockerContextManager.getCurrentContext()).Type === 'aci') { + // Replace 'docker-compose ' at the start of a string with 'docker compose ', and '--build' anywhere with '' + return command.replace(/^docker-compose /, 'docker compose ').replace(/--build/, ''); + } else { + return command; + } +} diff --git a/src/docker/ContextManager.ts b/src/docker/ContextManager.ts index 47f64a08ad..d1c8488b69 100644 --- a/src/docker/ContextManager.ts +++ b/src/docker/ContextManager.ts @@ -40,6 +40,7 @@ const defaultContext: Partial = { Description: 'Current DOCKER_HOST based configuration', }; +// These contexts are used by external consumers (e.g. the "Remote - Containers" extension), and should NOT be changed type VSCodeContext = 'vscode-docker:aciContext' | 'vscode-docker:newSdkContext' | 'vscode-docker:newCliPresent'; export interface ContextManager {