Documentation
¶
Index ¶
- func AutoDetectWSLDaemon() bool
- func AutoDetectWSLDaemonFor(host string) bool
- type DockerRuntime
- func (d *DockerRuntime) Create(ctx context.Context, spec *types.ContainerSpec) (string, error)
- func (d *DockerRuntime) Delete(ctx context.Context, id string) error
- func (d *DockerRuntime) Describe(ctx context.Context, id string) (*containerruntime.RuntimeDescription, error)
- func (d *DockerRuntime) Endpoint() (string, string)
- func (d *DockerRuntime) EnsureImage(ctx context.Context, imageName string, pullPolicy string) error
- func (d *DockerRuntime) Exec(ctx context.Context, id string, cmd []string) (string, error)
- func (d *DockerRuntime) HealthCheck(ctx context.Context) error
- func (d *DockerRuntime) Inspect(ctx context.Context, id string) (*containerruntime.RuntimeInspection, error)
- func (d *DockerRuntime) Logs(ctx context.Context, id string, tail int) (string, error)
- func (d *DockerRuntime) Monitor(ctx context.Context, runtimeID string) error
- func (d *DockerRuntime) Name() string
- func (d *DockerRuntime) OpenTerminal(ctx context.Context, id string, opts containerruntime.TerminalOptions) (containerruntime.TerminalSession, error)
- func (d *DockerRuntime) Pause(ctx context.Context, id string) error
- func (d *DockerRuntime) Resume(ctx context.Context, id string) error
- func (d *DockerRuntime) ServerVersion(ctx context.Context) (string, error)
- func (d *DockerRuntime) SetEventHandler(h containerruntime.RuntimeEventHandler)
- func (d *DockerRuntime) Start(ctx context.Context, id string) error
- func (d *DockerRuntime) Stop(ctx context.Context, id string) error
- func (d *DockerRuntime) WSLDaemon() bool
- type DockerRuntimeOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoDetectWSLDaemon ¶ added in v0.2.3
func AutoDetectWSLDaemon() bool
AutoDetectWSLDaemon 依据 DOCKER_HOST 推断是否连接 WSL2 内的 dockerd。
判据:Windows 宿主 + DOCKER_HOST 为 tcp:// 或 http://。 npipe://(Docker Desktop 的 Windows daemon)不参与推断:它的文件系统就是 Windows, bind mount 的 Source 仍应是 Windows 盘符路径。
func AutoDetectWSLDaemonFor ¶ added in v0.2.4
AutoDetectWSLDaemonFor 依据显式 daemon 地址 host 与 DOCKER_HOST 推断是否连接 WSL2 内的 dockerd。
host 是预置(provision)流程解析出的 daemon 地址(如 tcp://172.24.1.10:2375); 为空时只看 DOCKER_HOST。判定条件:
- 仅在 Windows 上成立:Linux 的 provision 产出的同样是 unix:// 本机 socket, 其文件系统与宿主一致,不存在 /mnt/<drive> 这层翻译;
- 地址为 tcp:// 或 http://(unix:// / npipe:// 都表示「与宿主共享文件系统」)。
Types ¶
type DockerRuntime ¶
type DockerRuntime struct {
// contains filtered or unexported fields
}
func NewDockerRuntime ¶
func NewDockerRuntime(opts ...DockerRuntimeOption) *DockerRuntime
func (*DockerRuntime) Create ¶
func (d *DockerRuntime) Create(ctx context.Context, spec *types.ContainerSpec) (string, error)
func (*DockerRuntime) Describe ¶ added in v0.1.4
func (d *DockerRuntime) Describe(ctx context.Context, id string) (*containerruntime.RuntimeDescription, error)
func (*DockerRuntime) Endpoint ¶ added in v0.2.4
func (d *DockerRuntime) Endpoint() (string, string)
Endpoint satisfies containerruntime.RuntimeEndpointReporter. 返回最终生效的 daemon 地址(显式 host 优先,否则为 Docker SDK 从环境变量推断的结果)。
func (*DockerRuntime) EnsureImage ¶
func (*DockerRuntime) HealthCheck ¶ added in v0.2.2
func (d *DockerRuntime) HealthCheck(ctx context.Context) error
HealthCheck satisfies containerruntime.RuntimeHealthChecker. 通过 docker client 的 Ping 探测 daemon 是否可达(socket 权限 / daemon 未启动都会在这里暴露)。
func (*DockerRuntime) Inspect ¶
func (d *DockerRuntime) Inspect(ctx context.Context, id string) (*containerruntime.RuntimeInspection, error)
func (*DockerRuntime) Monitor ¶
func (d *DockerRuntime) Monitor(ctx context.Context, runtimeID string) error
func (*DockerRuntime) Name ¶
func (d *DockerRuntime) Name() string
func (*DockerRuntime) OpenTerminal ¶ added in v0.2.0
func (d *DockerRuntime) OpenTerminal(ctx context.Context, id string, opts containerruntime.TerminalOptions) (containerruntime.TerminalSession, error)
OpenTerminal 等价于 `docker exec -it <container> <command>`。
func (*DockerRuntime) ServerVersion ¶ added in v0.2.4
func (d *DockerRuntime) ServerVersion(ctx context.Context) (string, error)
ServerVersion satisfies containerruntime.RuntimeVersionReporter.
func (*DockerRuntime) SetEventHandler ¶
func (d *DockerRuntime) SetEventHandler(h containerruntime.RuntimeEventHandler)
func (*DockerRuntime) WSLDaemon ¶ added in v0.2.3
func (d *DockerRuntime) WSLDaemon() bool
WSLDaemon 报告当前是否按 WSL2 daemon 语义翻译挂载路径。
type DockerRuntimeOption ¶ added in v0.2.3
type DockerRuntimeOption func(*DockerRuntime)
DockerRuntimeOption 定制 DockerRuntime 的构造。
func WithHost ¶ added in v0.2.4
func WithHost(host string) DockerRuntimeOption
WithHost 显式指定 daemon 地址,绕过 FromEnv 的环境变量推断。
预置流程(provision.Manager.Start)产出的 endpoint 通过它注入, 使运行时地址由安装状态决定,而不是依赖外部设置的 DOCKER_HOST。
func WithPathMapper ¶ added in v0.2.3
func WithPathMapper(paths *containerruntime.PathMapper) DockerRuntimeOption
WithPathMapper 注入统一路径映射器(由装配层按 storage.base_dir + WSL 探测构建)。
func WithPublishPort ¶ added in v0.2.4
func WithPublishPort(publish bool) DockerRuntimeOption
WithPublishPort 让容器端口以随机宿主机端口发布(默认关闭)。
默认关闭:gobrave 通过容器 IP 直连应用,不需要占用宿主机端口, 多实例同时运行也不会冲突。开启后每次 create 都由 docker 分配空闲端口, 实际端口通过 Inspect 读回(HostPort)。