Help us shape the future of Go! Take the 2026 Go Developer Survey

nginx

package module
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithConfigFile

func WithConfigFile(hostPath string) testcontainers.CustomizeRequestOption

WithConfigFile mounts a custom nginx.conf file at /etc/nginx/nginx.conf in the container. The hostPath must be an absolute path to the configuration file on the host.

func WithCustomConfig

func WithCustomConfig(hostPath string) testcontainers.CustomizeRequestOption

WithCustomConfig mounts a configuration snippet at /etc/nginx/conf.d/default.conf in the container. The hostPath must be an absolute path to the configuration file on the host.

Types

type Container

type Container struct {
	testcontainers.Container
}

Container represents the Nginx container type used in the module.

func Run

Run creates an instance of the Nginx container type.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/testcontainers/testcontainers-go"
	"github.com/testcontainers/testcontainers-go/modules/nginx"
)

func main() {
	// runNginxContainer {
	ctx := context.Background()

	nginxContainer, err := nginx.Run(ctx, "nginx:1.25")
	defer func() {
		if err := testcontainers.TerminateContainer(nginxContainer); err != nil {
			log.Printf("failed to terminate container: %s", err)
		}
	}()
	if err != nil {
		log.Printf("failed to start container: %s", err)
		return
	}
	// }

	state, err := nginxContainer.State(ctx)
	if err != nil {
		log.Printf("failed to get container state: %s", err)
		return
	}

	fmt.Println(state.Running)

}
Output:
true
Example (HttpEndpoint)
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/testcontainers/testcontainers-go"
	"github.com/testcontainers/testcontainers-go/modules/nginx"
)

func main() {
	// httpEndpointExample {
	ctx := context.Background()

	nginxContainer, err := nginx.Run(ctx, "nginx:1.25")
	defer func() {
		if err := testcontainers.TerminateContainer(nginxContainer); err != nil {
			log.Printf("failed to terminate container: %s", err)
		}
	}()
	if err != nil {
		log.Printf("failed to start container: %s", err)
		return
	}

	httpEndpoint, err := nginxContainer.HTTPEndpoint(ctx)
	if err != nil {
		log.Printf("failed to get HTTP endpoint: %s", err)
		return
	}
	// }

	_ = httpEndpoint
	fmt.Println("got http endpoint")

}
Output:
got http endpoint

func (*Container) HTTPEndpoint

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

HTTPEndpoint returns the HTTP endpoint of the Nginx container, in the form "http://host:port".

func (*Container) HTTPSEndpoint

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

HTTPSEndpoint returns the HTTPS endpoint of the Nginx container, in the form "https://host:port".

Jump to

Keyboard shortcuts

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