Documentation
¶
Overview ¶
Package docker provides an explicitly constructed sandbox backed by a local Docker Engine. It uses the official Engine Go client and never pulls images.
Index ¶
- type Backend
- func (backend *Backend) Close() error
- func (backend *Backend) Delete(ctx context.Context, name string) (dabackend.DeleteResult, error)
- func (backend *Backend) Download(ctx context.Context, paths []string) []dabackend.DownloadResult
- func (backend *Backend) Edit(ctx context.Context, name, old, replacement string, replaceAll bool) (dabackend.EditResult, error)
- func (backend *Backend) Execute(ctx context.Context, command string, timeout time.Duration) (dabackend.ExecuteResult, error)
- func (backend *Backend) ExecuteWithOptions(ctx context.Context, command string, options dabackend.ExecuteOptions) (dabackend.ExecuteResult, error)
- func (backend *Backend) Glob(ctx context.Context, pattern, base string) (dabackend.GlobResult, error)
- func (backend *Backend) Grep(ctx context.Context, pattern string, options dabackend.GrepOptions) (dabackend.GrepResult, error)
- func (backend *Backend) ID() string
- func (backend *Backend) List(ctx context.Context, directory string) (dabackend.ListResult, error)
- func (backend *Backend) Read(ctx context.Context, name string, offset, limit int) (dabackend.ReadResult, error)
- func (backend *Backend) ReadBinary(ctx context.Context, name string, maxBytes int64) (dabackend.ReadResult, error)
- func (backend *Backend) Shutdown(ctx context.Context) error
- func (backend *Backend) Upload(ctx context.Context, uploads []dabackend.Upload) []dabackend.UploadResult
- func (backend *Backend) Workspace() string
- func (backend *Backend) Write(ctx context.Context, name, content string) (dabackend.WriteResult, error)
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend owns one Docker container and its mounted workspace. File operations are confined to the workspace; Execute runs inside the container.
func New ¶
New connects to Docker using the standard environment variables and API version negotiation, then creates and starts one owned container. Closing the backend also closes the Engine client created by this function.
func NewWithClient ¶
func NewWithClient(ctx context.Context, client *engineclient.Client, image string, options Options) (*Backend, error)
NewWithClient creates an owned container using a caller-managed Engine client. Closing the backend removes the container but does not close client.
func (*Backend) ExecuteWithOptions ¶
func (backend *Backend) ExecuteWithOptions(ctx context.Context, command string, options dabackend.ExecuteOptions) (dabackend.ExecuteResult, error)
func (*Backend) Grep ¶
func (backend *Backend) Grep(ctx context.Context, pattern string, options dabackend.GrepOptions) (dabackend.GrepResult, error)
func (*Backend) ReadBinary ¶
func (*Backend) Shutdown ¶
Shutdown removes the owned container and, when the backend created it, its temporary workspace. A failed container removal leaves the workspace intact.
type Options ¶
type Options struct {
// Name optionally assigns a container name. Docker generates one otherwise.
Name string
// Workspace optionally supplies the host directory mounted at Workdir. When
// omitted, the backend creates a private temporary directory removed by Close.
Workspace string
// Workdir defaults to /workspace.
Workdir string
// User defaults to the current numeric uid:gid on Unix. Set it explicitly
// when the image requires a different identity.
User string
// Env adds container environment variables. HOME defaults to Workdir unless
// Env supplies it.
Env map[string]string
// Network defaults to none. Set it explicitly to grant network access.
Network string
// WritableRoot opts out of the read-only container root filesystem. The
// workspace and /tmp remain writable either way.
WritableRoot bool
// Resource limits use secure non-zero defaults. Negative values are invalid.
// A zero value selects the documented default rather than disabling a limit.
MemoryBytes int64
CPUs float64
PidsLimit int64
DefaultTimeout time.Duration
MaxOutput int
MaxFileSize int64
MaxVideoSize int64
MaxResults int
}
Options controls a Docker sandbox created and owned by New or NewWithClient.