PrepareExec adds a callback to a container exec in the fake server.

This function will be called whenever the given exec id is started, and the given exec id will remain in the "Running" start while the function is running, so it's useful for emulating an exec that runs for two seconds, for example:

opts := docker.CreateExecOptions{
    AttachStdin:  true,
    AttachStdout: true,
    AttachStderr: true,
    Tty:          true,
    Cmd:          []string{"/bin/bash", "-l"},
// Client points to a fake server.
exec, err := client.CreateExec(opts)
// handle error
server.PrepareExec(exec.ID, func() {time.Sleep(2 * time.Second)})
err = client.StartExec(exec.ID, docker.StartExecOptions{Tty: true}) // will block for 2 seconds
// handle error

PrepareExec is referenced in 2 repositories