A Go context carries values across API and process boundaries and commonly carries request deadlines or cancellation signals. A task runner creates one with `context.Background()` and passes it to Docker client calls. section 3.4
The same context accompanies image pulling, container creation, startup, log retrieval, stopping, and removal. This makes the context an explicit argument at the boundary where the task runner asks the Docker client to act. section 3.4
Use an empty context for a container operation
`ctx := context.Background()` supplies a context to `ImagePull`; the runner then handles an error or copies the pull output to standard output. section 3.4
Listing 3.9 The start of our Run() method
func (d *Docker) Run() DockerResult {
ctx := context.Background()
reader, err := d.Client.ImagePull(
ctx, d.Config.Image, types.ImagePullOptions{})
if err != nil {
log.Printf("Error pulling image %s: %v\n", d.Config.Image, err)
return DockerResult{Error: err}
}
io.Copy(os.Stdout, reader)
}
Shows a minimal `Run` method creating a background context and passing it to `ImagePull`. section 3.4






