Skip to main content

DockerService

Docker container lifecycle management — create, list, inspect, start, stop, remove, exec, and pull operations.

Methods

MethodDescription
Create(ctx, hostname, opts)Create a new container
List(ctx, hostname, params)List containers
Inspect(ctx, hostname, id)Get detailed container info
Start(ctx, hostname, id)Start a stopped container
Stop(ctx, hostname, id, opts)Stop a running container
Remove(ctx, hostname, id, p)Remove a container
Exec(ctx, hostname, id, opts)Execute a command in a container
Pull(ctx, hostname, opts)Pull a container image

Request Types

The Docker service uses SDK-defined request types. Consumers never need to import gen.

TypeFields
DockerCreateOptsImage, Name, Command, Env, Ports, Volumes, AutoStart
DockerStopOptsTimeout
DockerListParamsState, Limit
DockerRemoveParamsForce
DockerPullOptsImage
DockerExecOptsCommand

Usage

import "github.com/retr0h/osapi/pkg/sdk/client"

c := client.New("http://localhost:8080", token)

// Pull an image
resp, err := c.Docker.Pull(ctx, "_any", client.DockerPullOpts{
Image: "nginx:latest",
})

// Create a container
autoStart := true
resp, err := c.Docker.Create(ctx, "_any", client.DockerCreateOpts{
Image: "nginx:latest",
Name: "web",
Ports: []string{"8080:80"},
AutoStart: &autoStart,
})

// List running containers
resp, err := c.Docker.List(ctx, "_any", &client.DockerListParams{
State: "running",
})

// Execute a command
resp, err := c.Docker.Exec(ctx, "_any", "web", client.DockerExecOpts{
Command: []string{"hostname"},
})

// Stop with timeout
resp, err := c.Docker.Stop(ctx, "_any", "web", client.DockerStopOpts{
Timeout: 30,
})

// Force remove
resp, err := c.Docker.Remove(ctx, "_any", "web", &client.DockerRemoveParams{
Force: true,
})

Permissions

OperationPermission
Createdocker:write
Listdocker:read
Inspectdocker:read
Startdocker:write
Stopdocker:write
Removedocker:write
Execdocker:execute
Pulldocker:write