dind

package module
v0.40.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	testcontainers.Container
}

Container represents the Docker in Docker container type used in the module

func Run

Run creates an instance of the Docker in Docker container type

Example
// runDinDContainer {
ctx := context.Background()

dindContainer, err := dind.Run(ctx, "docker:28.0.1-dind")
defer func() {
	if err := testcontainers.TerminateContainer(dindContainer); err != nil {
		log.Printf("failed to terminate container: %s", err)
	}
}()
if err != nil {
	log.Printf("failed to start container: %s", err)
	return
}
// }

// Retrieve the host where the DinD daemon is listening
// didnHost {
host, err := dindContainer.Host(ctx)
if err != nil {
	log.Printf("failed to get docker host: %s", err)
	return
}
// }

// getDockerClient {
cli, err := client.NewClientWithOpts(client.WithHost(host), client.WithAPIVersionNegotiation())
if err != nil {
	log.Printf("failed to create docker client: %s", err)
	return
}
// }

version, err := cli.ServerVersion(ctx)
if err != nil {
	log.Printf("failed to get server version: %s", err)
	return
}

fmt.Println(version.APIVersion)

// The output will vary depending on the Docker version used in the DinD container.
// This is the negotiated API version between the client and the server.

func (*Container) Host

func (c *Container) Host(ctx context.Context) (string, error)

Host returns the endpoint to connect to the Docker daemon running inside the DinD container.

func (*Container) LoadImage

func (c *Container) LoadImage(ctx context.Context, image string) (err error)

LoadImage loads an image into the DinD container. It creates a temporary file to save the image and then copies it to the container. This temporary file is deleted after the function returns.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL