Skip to content
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

Add support for Linux Docker Desktop rootless socket path #528

Merged
merged 1 commit into from
Apr 12, 2023
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
13 changes: 12 additions & 1 deletion src/docker/rootless-unix-socket-strategy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions src/docker/rootless-unix-socket-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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");
}
Expand Down