diff --git a/src/docker/rootless-unix-socket-strategy.test.ts b/src/docker/rootless-unix-socket-strategy.test.ts index 969ab27e2..31f2d8d1f 100644 --- a/src/docker/rootless-unix-socket-strategy.test.ts +++ b/src/docker/rootless-unix-socket-strategy.test.ts @@ -37,7 +37,7 @@ describe("RootlessUnixSocketStrategy", () => { expect((await strategy.getDockerClient()).uri).toEqual(`unix://${socketPath}`); }); - it("should return Docker client for socket from home dir", async () => { + it("should return Docker client for socket from home run dir", async () => { const socketPath = path.join(os.homedir(), ".docker", "run", "docker.sock"); mockExistsSync.mockImplementation((file) => file === socketPath); @@ -48,6 +48,17 @@ describe("RootlessUnixSocketStrategy", () => { expect((await strategy.getDockerClient()).uri).toEqual(`unix://${socketPath}`); }); + it("should return Docker client for socket from home desktop dir", async () => { + const socketPath = path.join(os.homedir(), ".docker", "desktop", "docker.sock"); + mockExistsSync.mockImplementation((file) => file === socketPath); + + const strategy = new RootlessUnixSocketStrategy("linux", {}); + await strategy.init(); + + expect(strategy.isApplicable()).toBe(true); + expect((await strategy.getDockerClient()).uri).toEqual(`unix://${socketPath}`); + }); + it("should return Docker client for socket from run dir", async () => { const socketPath = path.join("/run", "user", `${os.userInfo().uid}`, "docker.sock"); mockExistsSync.mockImplementation((file) => file === socketPath); diff --git a/src/docker/rootless-unix-socket-strategy.ts b/src/docker/rootless-unix-socket-strategy.ts index 767fe3b76..65b0fbae9 100644 --- a/src/docker/rootless-unix-socket-strategy.ts +++ b/src/docker/rootless-unix-socket-strategy.ts @@ -20,7 +20,12 @@ export class RootlessUnixSocketStrategy implements DockerClientStrategy { return; } - this.socketPath = [this.getSocketPathFromEnv(), this.getSocketPathFromHomeDir(), this.getSocketPathFromRunDir()] + this.socketPath = [ + this.getSocketPathFromEnv(), + this.getSocketPathFromHomeRunDir(), + this.getSocketPathFromHomeDesktopDir(), + this.getSocketPathFromRunDir(), + ] .filter(isDefined) .find((candidateSocketPath) => existsSync(candidateSocketPath)); @@ -37,10 +42,14 @@ export class RootlessUnixSocketStrategy implements DockerClientStrategy { } } - private getSocketPathFromHomeDir(): string { + private getSocketPathFromHomeRunDir(): string { return path.join(os.homedir(), ".docker", "run", "docker.sock"); } + private getSocketPathFromHomeDesktopDir(): string { + return path.join(os.homedir(), ".docker", "desktop", "docker.sock"); + } + private getSocketPathFromRunDir(): string { return path.join("/run", "user", `${os.userInfo().uid}`, "docker.sock"); }