mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-22 21:50:47 -05:00
feat: honor DOCKER_HOST for Docker daemon resolution (#4)
Resolve the Docker endpoint from DOCKER_HOST (with the legacy DOCKER_SOCK override and an OS default fallback) so Podman, rootless setups, and remote Docker contexts work without assuming /var/run/docker.sock. start/az start/gcp start bind-mount the resolved unix socket or pass a remote tcp:// daemon through via DOCKER_HOST; doctor's docker.socket check reports the resolved endpoint. Adds DockerHostResolveTest and README documentation. Closes #3
This commit is contained in:
1 parent
67468966ce
commit
6862c0dd81
8 files changed
+204
-11
No files matched your search
@@ -0,0 +1,84 @@
|
||||
package io.floci.cli.unit;
|
||||
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerClient.DockerHost;
|
||||
import io.floci.cli.docker.DockerClient.Kind;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class DockerHostResolveTest {
|
||||
|
||||
@Test
|
||||
void rootlessPodmanUnixSocket() {
|
||||
DockerHost h = DockerClient.parseDockerHost(
|
||||
"unix:///run/user/1000/podman/podman.sock", null, "Linux");
|
||||
assertEquals(Kind.UNIX, h.kind());
|
||||
assertEquals("/run/user/1000/podman/podman.sock", h.socketPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rootfulDockerUnixSocket() {
|
||||
DockerHost h = DockerClient.parseDockerHost("unix:///var/run/docker.sock", null, "Linux");
|
||||
assertEquals(Kind.UNIX, h.kind());
|
||||
assertEquals("/var/run/docker.sock", h.socketPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void remoteTcpDaemon() {
|
||||
DockerHost h = DockerClient.parseDockerHost("tcp://10.0.0.1:2375", null, "Linux");
|
||||
assertEquals(Kind.TCP, h.kind());
|
||||
assertNull(h.socketPath());
|
||||
assertEquals("tcp://10.0.0.1:2375", h.raw());
|
||||
}
|
||||
|
||||
@Test
|
||||
void barePathTreatedAsUnixSocket() {
|
||||
DockerHost h = DockerClient.parseDockerHost("/run/user/1000/podman/podman.sock", null, "Linux");
|
||||
assertEquals(Kind.UNIX, h.kind());
|
||||
assertEquals("/run/user/1000/podman/podman.sock", h.socketPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void npipeScheme() {
|
||||
DockerHost h = DockerClient.parseDockerHost("npipe:////./pipe/podman", null, "Windows 11");
|
||||
assertEquals(Kind.NPIPE, h.kind());
|
||||
assertEquals("//./pipe/podman", h.socketPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dockerHostTakesPrecedenceOverDockerSock() {
|
||||
DockerHost h = DockerClient.parseDockerHost(
|
||||
"unix:///run/podman/podman.sock", "/var/run/docker.sock", "Linux");
|
||||
assertEquals(Kind.UNIX, h.kind());
|
||||
assertEquals("/run/podman/podman.sock", h.socketPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fallsBackToDockerSock() {
|
||||
DockerHost h = DockerClient.parseDockerHost(null, "/custom/docker.sock", "Linux");
|
||||
assertEquals(Kind.UNIX, h.kind());
|
||||
assertEquals("/custom/docker.sock", h.socketPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void blankEnvIgnored() {
|
||||
DockerHost h = DockerClient.parseDockerHost(" ", " ", "Linux");
|
||||
assertEquals(Kind.UNIX, h.kind());
|
||||
assertEquals("/var/run/docker.sock", h.socketPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultLinuxSocket() {
|
||||
DockerHost h = DockerClient.parseDockerHost(null, null, "Linux");
|
||||
assertEquals(Kind.UNIX, h.kind());
|
||||
assertEquals("/var/run/docker.sock", h.socketPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultWindowsPipe() {
|
||||
DockerHost h = DockerClient.parseDockerHost(null, null, "Windows 11");
|
||||
assertEquals(Kind.NPIPE, h.kind());
|
||||
assertEquals("\\\\.\\pipe\\docker_engine", h.socketPath());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user