docker

package
v0.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: Apache-2.0, MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package docker deploys apps to a Docker engine, local or remote over SSH.

Index

Constants

View Source
const SafetyCapPercent = 75

SafetyCapPercent is how much of the server's memory an app with no limit of its own may use: enough for nearly anything, while leaving room for the other apps and for Skiff to keep running if one runs away.

Variables

This section is empty.

Functions

func Forward added in v0.5.4

func Forward(sshTarget string, remotePort int) (localPort int, stop func(), err error)

Forward opens an ssh tunnel from a free local port to 127.0.0.1:remotePort on sshTarget, so an app that listens only on its server's loopback can still be reached from here. Call stop when done.

func RouterOn added in v0.5.4

func RouterOn(sshTarget string) (running, known bool)

RouterOn reports whether a box runs Skiff's router. known is false when ssh itself failed, so nothing can be said.

func SSHHostname

func SSHHostname(target string) string

Types

type AppImage added in v0.2.0

type AppImage struct {
	App     string
	Ref     string
	Created time.Time
}

type ContainerInfo

type ContainerInfo struct {
	Name    string
	Created time.Time
	App     string // skiff.app label; "" for containers not tied to an app
	Port    int    // skiff.port label
	Running bool
}

type ContainerMeta added in v0.2.0

type ContainerMeta struct {
	Created time.Time
	Labels  map[string]string
}

type ContainerResource

type ContainerResource struct {
	App       string
	Container string
	CPUPerc   float64 // percent of one core; can exceed 100 on multi-core
	MemBytes  int64
	MemLimit  int64
	Restarts  int
}

type ContainerRuntime added in v0.2.0

type ContainerRuntime struct {
	Image    string
	Env      map[string]string
	Cmd      []string
	Networks []string
	Mounts   []Mount
	Labels   map[string]string
	Running  bool
}

type DBRunSpec

type DBRunSpec struct {
	Name       string
	Image      string
	Network    string
	Volume     string // named volume for persistence
	MountAt    string // where the volume mounts inside the container
	Env        map[string]string
	Cmd        []string          // optional command/args after the image
	Labels     map[string]string // ownership + kind labels
	Port       int               // container port (published on the host when Publish is set)
	Publish    bool              // expose Port on 0.0.0.0 for external access
	Entrypoint string            // optional --entrypoint override (e.g. "sh" to fix TLS cert perms)
	Binds      []string          // extra bind mounts, "host:container[:ro]" (e.g. the TLS cert dir)
}

DBRunSpec runs a managed resource (a database), deliberately unlabeled with skiff=1 so the app reaper leaves it alone.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

func For

func For(host string) *Engine

func Local

func Local() *Engine

func Remote

func Remote(sshTarget string) *Engine

func (*Engine) AppContainerKeys added in v0.2.0

func (e *Engine) AppContainerKeys() (map[string]string, error)

AppContainerKeys maps each running app container to its app.

func (*Engine) AppContainers

func (e *Engine) AppContainers(app string) []string

AppContainers lists every container (running or not) for an app, so all stale versions get retired, not just the registry's last-recorded one.

func (*Engine) AppImageTags

func (e *Engine) AppImageTags(app string) []string

AppImageTags lists an app's retained image tags (excluding :latest and <none>), relying on docker's default created-descending order — newest first — for pruning.

func (*Engine) AppImages added in v0.2.0

func (e *Engine) AppImages() ([]AppImage, error)

AppImages lists every skiff-<app> image tag on the engine.

func (*Engine) AppResourceStats

func (e *Engine) AppResourceStats() ([]ContainerResource, error)

func (*Engine) AppStates

func (e *Engine) AppStates() (map[string]string, error)

AppStates maps each skiff app to its container state; running wins when an app has more than one container (e.g. mid-rollout).

func (*Engine) AppVolumes added in v0.5.0

func (e *Engine) AppVolumes(app string) []string

AppVolumes names every volume created for an app.

func (*Engine) Available

func (e *Engine) Available() error

func (*Engine) BuildFromDockerfile

func (e *Engine) BuildFromDockerfile(ctx context.Context, tag, dockerfile, contextDir string, pull bool, out io.Writer) error

BuildFromDockerfile builds contextDir into tag. With pull, every base image comes from its registry, so a build can't use images other apps left on this machine.

func (*Engine) ConnectNetwork

func (e *Engine) ConnectNetwork(network, container string) error

ConnectNetwork attaches a container to an additional network; an already-connected container returns a benign error.

func (*Engine) ContainerImages added in v0.2.0

func (e *Engine) ContainerImages() (map[string]bool, error)

ContainerImages returns the image of every container, running or not.

func (*Engine) ContainerMeta added in v0.2.0

func (e *Engine) ContainerMeta(name string) (ContainerMeta, error)

func (*Engine) Containers

func (e *Engine) Containers() ([]string, error)

func (*Engine) DialContainer added in v0.5.0

func (e *Engine) DialContainer(ctx context.Context, container, host, port string) (net.Conn, error)

DialContainer opens a connection to an address as seen from inside a container, through `docker exec` and the nc in its image. It reaches services that publish no port, and works where the host can't route to container IPs.

func (*Engine) EnsureAppVolume added in v0.5.0

func (e *Engine) EnsureAppVolume(volume, app, name string) error

EnsureAppVolume creates an app's named volume, labelled with its owner so it can be listed and removed with the app; an existing volume is left as is.

func (*Engine) EnsureNetwork

func (e *Engine) EnsureNetwork(name string) error

func (*Engine) Exec

func (e *Engine) Exec(ctx context.Context, container string, cmd []string, stdin io.Reader, stdout io.Writer) error

Exec runs a command inside a container, wiring stdin/stdout to the given streams — used to dump a database and pipe a dump back in.

func (*Engine) FollowLogs added in v0.3.0

func (e *Engine) FollowLogs(ctx context.Context, container string, since time.Time, line func(ts time.Time, stream, text string)) error

FollowLogs streams a container's output from since onward, calling line for each one with docker's timestamp; it returns when the container stops or ctx ends.

func (*Engine) HostPort

func (e *Engine) HostPort(name string, containerPort int) (int, error)

func (*Engine) ImageDigest added in v0.5.0

func (e *Engine) ImageDigest(image string) string

ImageDigest is the registry digest a pulled image came from, if it has one.

func (*Engine) ImageExists

func (e *Engine) ImageExists(tag string) bool

func (*Engine) ImagePort added in v0.5.0

func (e *Engine) ImagePort(image string) int

ImagePort is the lowest TCP port the image declares with EXPOSE, or 0 when it declares none.

func (*Engine) IsRemote

func (e *Engine) IsRemote() bool

func (*Engine) Logs

func (e *Engine) Logs(container string, follow bool, tail string, out io.Writer) error

func (*Engine) PruneBuildCache added in v0.2.0

func (e *Engine) PruneBuildCache(olderThan time.Duration) error

func (*Engine) PruneDanglingImages added in v0.2.0

func (e *Engine) PruneDanglingImages() error

func (*Engine) Pull added in v0.5.0

func (e *Engine) Pull(ctx context.Context, image string, auth *RegistryAuth, out io.Writer) error

Pull fetches an image, streaming docker's progress to out. With auth, the pull uses a throwaway docker config so the credentials are never written to the user's own.

func (*Engine) PullImage

func (e *Engine) PullImage(image string) error

func (*Engine) Remove

func (e *Engine) Remove(name string) error

func (*Engine) RemoveImage

func (e *Engine) RemoveImage(tag string) error

func (*Engine) RemoveVolume

func (e *Engine) RemoveVolume(name string) error

func (*Engine) Routes

func (e *Engine) Routes() ([]Route, error)

func (*Engine) Run

func (e *Engine) Run(s RunSpec) (int, error)

func (*Engine) RunDatabase

func (e *Engine) RunDatabase(s DBRunSpec) (int, error)

RunDatabase (re)creates a managed database container, returning the published host port when Publish is set (0 otherwise); reusing the same name + volume preserves the data.

func (*Engine) RunOnce

func (e *Engine) RunOnce(ctx context.Context, image string, env map[string]string, network string, volumes []Mount, cmd string) (string, error)

RunOnce runs a throwaway container executing a shell command (sh -c), for release commands (migrations) and scheduled jobs.

func (*Engine) RunWorker

func (e *Engine) RunWorker(s WorkerSpec) error

func (*Engine) RunningContainers added in v0.2.0

func (e *Engine) RunningContainers() ([]string, error)

RunningContainers names every running container.

func (*Engine) Runtime added in v0.2.0

func (e *Engine) Runtime(name string) (ContainerRuntime, error)

Runtime reads how a container was started: image, environment, command, networks and volumes.

func (*Engine) SkiffContainers

func (e *Engine) SkiffContainers() []ContainerInfo

func (*Engine) Start added in v0.2.0

func (e *Engine) Start(container string) error

func (*Engine) State

func (e *Engine) State(container string) string

func (*Engine) StatsFor added in v0.2.0

func (e *Engine) StatsFor(appOf map[string]string) ([]ContainerResource, error)

StatsFor samples the named containers once, reporting each under the key it maps to.

func (*Engine) Stop

func (e *Engine) Stop(container string) error

func (*Engine) StreamLogs

func (e *Engine) StreamLogs(ctx context.Context, container string, out io.Writer) error

func (*Engine) StreamLogsSSE

func (e *Engine) StreamLogsSSE(ctx context.Context, container string, w io.Writer, flush func())

func (*Engine) Tag

func (e *Engine) Tag(src, dst string) error

func (*Engine) VolumeExists added in v0.3.0

func (e *Engine) VolumeExists(name string) bool

func (*Engine) VolumeSizes added in v0.5.0

func (e *Engine) VolumeSizes() map[string]int64

VolumeSizes reports how much each volume holds; docker walks every volume to answer, so callers should cache it.

func (*Engine) WatchOOM added in v0.5.1

func (e *Engine) WatchOOM(ctx context.Context, fn func(app, container string)) error

WatchOOM calls fn with the app whenever one of its containers is killed for exceeding its memory limit, until ctx ends. It reports an error when events can't be read, and needs the local Docker socket.

func (*Engine) WorkerContainerKeys added in v0.3.0

func (e *Engine) WorkerContainerKeys() (map[string]string, error)

WorkerContainerKeys maps each running worker container to its app.

func (*Engine) WorkerContainers

func (e *Engine) WorkerContainers(app string) []string

WorkerContainers lists an app's worker containers (running or not); all of them when app is "".

type Mount added in v0.2.0

type Mount struct {
	Name        string
	Destination string
}

type RegistryAuth added in v0.5.0

type RegistryAuth struct {
	Host     string
	Username string
	Password string
}

RegistryAuth signs in to the image's registry for a single pull.

type Route

type Route struct {
	App      string
	HostPort int
}

type RunSpec

type RunSpec struct {
	Public        bool // on all interfaces, for a box with no router in front of its apps
	Name          string
	App           string // app name, for the skiff.app route label
	Image         string
	ContainerPort int
	Memory        string // optional, e.g. "512m"
	CPU           string // optional, e.g. "0.5"
	Env           map[string]string
	Network       string // optional docker network to join (for reaching managed resources by name)
	Labels        map[string]string
	Volumes       []Mount
}

type WorkerSpec

type WorkerSpec struct {
	Name    string
	App     string
	Image   string
	Command string // run via sh -c
	Env     map[string]string
	Network string
	Volumes []Mount
	Memory  string
	CPU     string
}

WorkerSpec runs a long-lived background process with no published port or routing labels, so the edge router never targets it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL