run

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package run provides configuration options for running containers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt

type Opt func(*Options) error

Opt is a configuration option to run a container using github.com/thediveo/morbyd.Session.Run. Please see also Options for more information.

func ClearLabels

func ClearLabels() Opt

ClearLabels clears any labels inherited from the [Session] when creating a new container.

func WithAllPortsPublished

func WithAllPortsPublished() Opt

WithAllPortsPublished instructs Docker to publish all exposed ports on the host. Use with great care.

func WithAutoRemove

func WithAutoRemove() Opt

WithAutoRemove removes the container after it has stopped.

func WithCapAdd

func WithCapAdd(cap string) Opt

WithCapAdd adds an individual kernel capabilities to the initial process in the container.

func WithCapDropAll

func WithCapDropAll() Opt

WithCapDropAll drops all kernel capabilities for the initial process in the container.

Please note that we don't provide dropping individual capabilities on purpose: the default set of Docker container capabilities depend on the Docker engine and Linux kernel, so this would result in non-deterministic behavior. Drop them all, or drop none.

func WithCgroupnsMode

func WithCgroupnsMode(mode string) Opt

WithCgroupnsMode configures the cgroup namespace to use when creating the new container; it can be either “” (empty, use the daemon's default) configuration, “private”, or “host”.

func WithCombinedOutput

func WithCombinedOutput(w io.Writer) Opt

WithCombinedOutput sends the container's stdout and stderr to the specified io.Writer. This also automatically attaches the container's stdout and stderr after the container has been created.

Please note that you should WithCombinedOutput when using [WithTTYP],as Docker then combines the container's stdout and stderr into a single output stream.

func WithCommand

func WithCommand(cmd ...string) Opt

WithCommand sets the optional command to execute at container start.

func WithConsoleSize

func WithConsoleSize(width, height uint) Opt

WithConsoleSize sets with width and height of the pseudo TTY; please note the width-height order in contrast to the Docker API order.

func WithCustomInit

func WithCustomInit() Opt

func WithDemuxedOutput

func WithDemuxedOutput(out io.Writer, err io.Writer) Opt

WithDemuxedOutput disables the TTY option in order to send the container's stdout and stderr properly separated to the specified out and err io.Writer.

It is a known limitation of the (pseudo) TTY to combine both stdout and stderr of the container's output streams, and there is no way for Docker (and thus for us) to demultiplex this output sludge after the fact.

func WithDevice

func WithDevice(dev string) Opt

WithDevice specifies a host device to be added to the container to be created. The format is either:

  • /dev/foo
  • /dev/foo:/dev/bar
  • /dev/foo:/dev/bar:rwm

WithDevice will panic if the first (host path) element is empty. If the container path is empty, the same path as in the host is assumed.The cgroup permissions default to “rwm”.

See also: https://docs.docker.com/engine/reference/commandline/container_run/#device

func WithEnvVars

func WithEnvVars(vars ...string) Opt

WithEnvVars adds multiple environment variables to the container to be started.

func WithHostname

func WithHostname(host string) Opt

WithHostname configures the host name to use inside the container.

func WithIPCMode

func WithIPCMode(mode string) Opt

WithIPCMode configures the IPC namespace to use when creating the new container; it can be either “” (empty, use the daemon's default), “none” (private, but without /dev/shm mounted), “private”, “shareable”, “host”, or container:NAMEID”.

func WithInput

func WithInput(r io.Reader) Opt

WithInput sends input data from the specified io.Reader to the container's stdin. For this, it allocates a stdin for the container when creating it and then attaches to this stdin after creation.

func WithLabel

func WithLabel(label string) Opt

WithLabel adds a label in “key=value” format to the container's labels.

func WithLabels

func WithLabels(labels ...string) Opt

WithLabels adds multiple labels in “key=value” format to the container's labels.

func WithMount

func WithMount(mnt string) Opt

WithMount adds a (bind) mount. Please see also Docker's Bind mounts documentation.

func WithName

func WithName(name string) Opt

WithName sets the optional name of the container to create.

func WithNetwork

func WithNetwork(net string) Opt

WithNetwork attaches the new container to a particular network. The nameid parameter either identifies a network by its name or ID, or can be in long format, consisting of comma-separated key-value pairs.

  • “bridge”
  • “name=bridge,ip=128.0.0.1”

Please do not confuse with WithNetworkMode mode, where the latter configures the Linux kernel net namespace to use.

func WithNetworkMode

func WithNetworkMode(mode string) Opt

WithNetworkMode configures the net(work) namespace to use when creating the new container; it can be either “” (create a new one), “none”, “host”, or container:NAMEID”.

func WithPIDMode

func WithPIDMode(mode string) Opt

WithPIDMode configures the PID namespace to use when creating the new container; it can be either “” (create a new one), “host”, or container:NAMEID”.

func WithPrivileged

func WithPrivileged() Opt

WithPrivileged runs the container as privileged, including all capabilities and not masking out certain filesystem elements.

func WithReadOnlyRootfs

func WithReadOnlyRootfs() Opt

WithReadOnlyRootfs configures the new container to use a ready-only topmost layer.

func WithRestartPolicy

func WithRestartPolicy(policy string, maxretry int) Opt

WithRestartPolicy configures the restart policy (“no”, “always”, “on-failure”, “unless-stopped”) as well as the maximum attempts at restarting the container.

func WithSecurityOpt

func WithSecurityOpt(opt string) Opt

WithSecurityOpt configures an additional security option, such as “seccomp=unconfined”.

func WithStopSignal

func WithStopSignal(s string) Opt

WithStopSignal sets the name of the signal to be sent to its initial process when stopping the container.

func WithStopTimeout

func WithStopTimeout(secs int) Opt

WithStopTimeout sets the timeout (in seconds) to stop the container.

func WithTTY

func WithTTY() Opt

WithTTY allocates a pseudo TTY for the container's input and output.

Please note that using a TTY causes the container's stdout and stderr streams to get mixed together, so this option can be used only in combination with WithCombinedOutput. Specifying it after WithDemuxedOutput will cause the combined stdout+stderr output to appear only on the specified output io.Writer, whereas the specified error io.Writer won't receive any (error) output at all.

When WithTTY is used before WithDemuxedOutput, it'll become ineffective.

func WithTmpfs

func WithTmpfs(path string) Opt

WithTmpfs specifies the path inside the container to mount a new tmpfs instance on, using default options (unlimited size, world-writable).

func WithTmpfsOpts

func WithTmpfsOpts(path string, opts string) Opt

WithTmpfsOpts specifies the path isnide the container to mount a new tmpfs instance, as well as options in form of comma-separated “key=value”.

These options are available:

  • tmpfs-size=<bytes>; defaults to unlimited.
  • tmpfs-mode=<oct>, where <oct> format can be “700” and “0770”. Defaults to “1777”, that is, “world-writable”.

func WithVolume

func WithVolume(vol string) Opt

WithVolume adds a volume, in the format “source:target:options”. Please see also Docker's Volumes documentation.

- “/var”: an anonymous volume.

Options are comma-separated values:

  • “ro” for read-only; if not present, the default is read-write.
  • “z” (sharing content among multiple containers) or “Z” (content is private and unshared).

type Options

type Options struct {
	Name string
	In   io.Reader
	Out  io.Writer
	Err  io.Writer
	Conf container.Config
	Host container.HostConfig
	Net  network.NetworkingConfig
}

Options represent the plethora of options for creating a container from an image, attaching to it, and finally starting it, as well as additional options for handling the input and output of containers.

Please note that the defaults are:

  • don't allocate a pseudo TTY (a.k.a “-t” CLI arg); that means that the container gets fifos/pipes assigned to its stdin, stdout, and stderr, but not a pseudo TTY.
  • don't allocate stdin; use WithInput to set an io.Reader from which the container gets its stdin data stream fed. Please note that this additionally also sets OpenStdIn and StdinOnce. However, WithInput is not the same as the “-i” CLI arg; “-i” additionally sets AttachStdin, an API option that still is unknown to as what exactly it does during container creation...

Directories

Path Synopsis
Source: https://github.com/docker/cli/blob/v25.0.1/opts/mount.go
Source: https://github.com/docker/cli/blob/v25.0.1/opts/mount.go

Jump to

Keyboard shortcuts

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