Skip to content

Commit

Permalink
docs: improve docs for container methods (#2713)
Browse files Browse the repository at this point in the history
Improve the documentation for container Terminate and IsRunning methods.
  • Loading branch information
stevenh authored Aug 9, 2024
1 parent 7646ccf commit 125698c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 5 additions & 2 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ type Container interface {
MappedPort(context.Context, nat.Port) (nat.Port, error) // get externally mapped port for a container port
Ports(context.Context) (nat.PortMap, error) // Deprecated: Use c.Inspect(ctx).NetworkSettings.Ports instead
SessionID() string // get session id
IsRunning() bool
IsRunning() bool // IsRunning returns true if the container is running, false otherwise.
Start(context.Context) error // start the container
Stop(context.Context, *time.Duration) error // stop the container
Terminate(context.Context) error // terminate the container

// Terminate stops and removes the container and its image if it was built and not flagged as kept.
Terminate(ctx context.Context) error

Logs(context.Context) (io.ReadCloser, error) // Get logs of the container
FollowOutput(LogConsumer) // Deprecated: it will be removed in the next major release
StartLogProducer(context.Context, ...LogProductionOption) error // Deprecated: Use the ContainerRequest instead
Expand Down
13 changes: 9 additions & 4 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,20 @@ func (c *DockerContainer) Start(ctx context.Context) error {
return nil
}

// Stop will stop an already started container
// Stop stops the container.
//
// In case the container fails to stop
// gracefully within a time frame specified by the timeout argument,
// it is forcefully terminated (killed).
// In case the container fails to stop gracefully within a time frame specified
// by the timeout argument, it is forcefully terminated (killed).
//
// If the timeout is nil, the container's StopTimeout value is used, if set,
// otherwise the engine default. A negative timeout value can be specified,
// meaning no timeout, i.e. no forceful termination is performed.
//
// All hooks are called in the following order:
// - [ContainerLifecycleHooks.PreStops]
// - [ContainerLifecycleHooks.PostStops]
//
// If the container is already stopped, the method is a no-op.
func (c *DockerContainer) Stop(ctx context.Context, timeout *time.Duration) error {
err := c.stoppingHook(ctx)
if err != nil {
Expand Down

0 comments on commit 125698c

Please sign in to comment.