forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_socket.go
49 lines (39 loc) · 1.5 KB
/
docker_socket.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package testcontainersdocker
import (
"net/url"
"strings"
"github.com/docker/docker/client"
)
// DockerSocketSchema is the unix schema.
var DockerSocketSchema = "unix://"
// DockerSocketPath is the path to the docker socket under unix systems.
var DockerSocketPath = "/var/run/docker.sock"
// DockerSocketPathWithSchema is the path to the docker socket under unix systems with the unix schema.
var DockerSocketPathWithSchema = DockerSocketSchema + DockerSocketPath
// TCPSchema is the tcp schema.
var TCPSchema = "tcp://"
// WindowsDockerSocketPath is the path to the docker socket under windows systems.
var WindowsDockerSocketPath = "//var/run/docker.sock"
func init() {
const DefaultDockerHost = client.DefaultDockerHost
u, err := url.Parse(DefaultDockerHost)
if err != nil {
// unsupported default host specified by the docker client package,
// so revert to the default unix docker socket path
return
}
switch u.Scheme {
case "unix", "npipe":
DockerSocketSchema = u.Scheme + "://"
DockerSocketPath = u.Path
if !strings.HasPrefix(DockerSocketPath, "/") {
// seeing as the code in this module depends on DockerSocketPath having
// a slash (`/`) prefix, we add it here if it is missing.
// for the known environments, we do not foresee how the socket-path
// should miss the slash, however this extra if-condition is worth to
// save future pain from innocent users.
DockerSocketPath = "/" + DockerSocketPath
}
DockerSocketPathWithSchema = DockerSocketSchema + DockerSocketPath
}
}