diff --git a/docker.go b/docker.go index ead32a6ad2..fe1952c839 100644 --- a/docker.go +++ b/docker.go @@ -951,6 +951,8 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque req.Labels[k] = v } } + } else { + p.printReaperBanner("container") } if err = req.Validate(); err != nil { @@ -1164,6 +1166,8 @@ func (p *DockerProvider) ReuseOrCreateContainer(ctx context.Context, req Contain if err != nil { return nil, fmt.Errorf("%w: connecting to reaper failed", err) } + } else { + p.printReaperBanner("container") } dc := &DockerContainer{ ID: c.ID, @@ -1323,6 +1327,8 @@ func (p *DockerProvider) CreateNetwork(ctx context.Context, req NetworkRequest) req.Labels[k] = v } } + } else { + p.printReaperBanner("network") } response, err := p.client.NetworkCreate(ctx, req.Name, nc) @@ -1381,6 +1387,15 @@ func (p *DockerProvider) GetGatewayIP(ctx context.Context) (string, error) { return ip, nil } +func (p *DockerProvider) printReaperBanner(resource string) { + ryukDisabledMessage := ` + ********************************************************************************************** + Ryuk has been disabled for the ` + resource + `. This can cause unexpected behavior in your environment. + More on this: https://golang.testcontainers.org/features/garbage_collector/ + **********************************************************************************************` + p.Logger.Printf(ryukDisabledMessage) +} + func inAContainer() bool { // see https://github.com/testcontainers/testcontainers-java/blob/3ad8d80e2484864e554744a4800a81f6b7982168/core/src/main/java/org/testcontainers/dockerclient/DockerClientConfigUtils.java#L15 if _, err := os.Stat("/.dockerenv"); err == nil { diff --git a/docs/features/garbage_collector.md b/docs/features/garbage_collector.md index 3fa87eeb5d..c52fcd29d5 100644 --- a/docs/features/garbage_collector.md +++ b/docs/features/garbage_collector.md @@ -37,9 +37,13 @@ container labels to determine which resources were created by the package to determine the entities that are safe to remove. If a container is running for more than 10 seconds, it will be killed. -!!!tip +!!!warning + + This feature can be disabled when creating a container or a network, + but it can cause **unexpected behavior** in your environment. - This feature can be disabled when creating a container. + We recommend using it only for Continuous Integration services that have their + own mechanism to clean up resources. Even if you do not call Terminate, Ryuk ensures that the environment will be kept clean and even cleans itself when there is nothing left to do.