Documentation ¶
Overview ¶
Package dockerutil is a collection of utility functions, primarily for testing.
Index ¶
- func EnsureSupportedDockerVersion()
- func LinkArg(source *Docker, target string) string
- func MountArg(source, target string, mode MountMode) string
- func PrepareFiles(names ...string) (string, error)
- func Pull(image string) error
- func RuntimePath() (string, error)
- type Docker
- func (d *Docker) Checkpoint(name string) error
- func (d *Docker) CleanUp()
- func (d *Docker) Create(args ...string) error
- func (d *Docker) Exec(args ...string) (string, error)
- func (d *Docker) ExecAsUser(user string, args ...string) (string, error)
- func (d *Docker) ExecWithFlags(flags []string, args ...string) (string, error)
- func (d *Docker) ExecWithTerminal(args ...string) (*exec.Cmd, *os.File, error)
- func (d *Docker) FindIP() (string, error)
- func (d *Docker) FindPort(sandboxPort int) (int, error)
- func (d *Docker) ID() (string, error)
- func (d *Docker) Logs() (string, error)
- func (d *Docker) Pause() error
- func (d *Docker) Remove() error
- func (d *Docker) Restore(name string) error
- func (d *Docker) Run(args ...string) error
- func (d *Docker) RunFg(args ...string) (string, error)
- func (d *Docker) RunWithPty(args ...string) (*exec.Cmd, *os.File, error)
- func (d *Docker) SandboxPid() (int, error)
- func (d *Docker) Start() error
- func (d *Docker) Stop() error
- func (d *Docker) Unpause() error
- func (d *Docker) Wait(timeout time.Duration) (syscall.WaitStatus, error)
- func (d *Docker) WaitForOutput(pattern string, timeout time.Duration) (string, error)
- func (d *Docker) WaitForOutputSubmatch(pattern string, timeout time.Duration) ([]string, error)
- type MountMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureSupportedDockerVersion ¶
func EnsureSupportedDockerVersion()
EnsureSupportedDockerVersion checks if correct docker is installed.
func PrepareFiles ¶
PrepareFiles creates temp directory to copy files there. The sandbox doesn't have access to files in the test dir.
func Pull ¶
Pull pulls a docker image. This is used in tests to isolate the time to pull the image off the network from the time to actually start the container, to avoid timeouts over slow networks.
func RuntimePath ¶
RuntimePath returns the binary path for the current runtime.
Types ¶
type Docker ¶
Docker contains the name and the runtime of a docker container.
func MakeDocker ¶
MakeDocker sets up the struct for a Docker container. Names of containers will be unique.
func (*Docker) Checkpoint ¶
Checkpoint calls 'docker checkpoint'.
func (*Docker) CleanUp ¶
func (d *Docker) CleanUp()
CleanUp kills and deletes the container (best effort).
func (*Docker) ExecAsUser ¶
ExecAsUser calls 'docker exec' as the given user with the arguments provided.
func (*Docker) ExecWithFlags ¶
ExecWithFlags calls 'docker exec <flags> name <args>'.
func (*Docker) ExecWithTerminal ¶
ExecWithTerminal calls 'docker exec -it' with the arguments provided and attaches a pty to stdio.
func (*Docker) FindPort ¶
FindPort returns the host port that is mapped to 'sandboxPort'. This calls docker to allocate a free port in the host and prevent conflicts.
func (*Docker) Run ¶
Run calls 'docker run' with the arguments provided. The container starts running in the background and the call returns immediately.
func (*Docker) RunFg ¶
RunFg calls 'docker run' with the arguments provided in the foreground. It blocks until the container exits and returns the output.
func (*Docker) RunWithPty ¶
RunWithPty is like Run but with an attached pty.
func (*Docker) SandboxPid ¶
SandboxPid returns the PID to the sandbox process.
func (*Docker) Wait ¶
Wait waits for container to exit, up to the given timeout. Returns error if wait fails or timeout is hit. Returns the application return code otherwise. Note that the application may have failed even if err == nil, always check the exit code.
func (*Docker) WaitForOutput ¶
WaitForOutput calls 'docker logs' to retrieve containers output and searches for the given pattern.