MCPcopy Index your code
hub / github.com/testcontainers/testcontainers-go / ExampleContainer_Host

Function ExampleContainer_Host

docker_test.go:726–762  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

724}
725
726func ExampleContainer_Host() {
727 ctx := context.Background()
728
729 nginxC, err := Run(ctx, nginxAlpineImage,
730 WithExposedPorts("80/tcp"),
731 WithWaitStrategy(wait.ForHTTP("/").WithStartupTimeout(10*time.Second)),
732 )
733 defer func() {
734 if err := TerminateContainer(nginxC); err != nil {
735 log.Printf("failed to terminate container: %s", err)
736 }
737 }()
738 if err != nil {
739 log.Printf("failed to create container: %s", err)
740 return
741 }
742 // containerHost {
743 ip, err := nginxC.Host(ctx)
744 if err != nil {
745 log.Printf("failed to create container: %s", err)
746 return
747 }
748 // }
749 fmt.Println(ip)
750
751 state, err := nginxC.State(ctx)
752 if err != nil {
753 log.Printf("failed to get container state: %s", err)
754 return
755 }
756
757 fmt.Println(state.Running)
758
759 // Output:
760 // localhost
761 // true
762}
763
764func ExampleContainer_Start() {
765 ctx := context.Background()

Callers

nothing calls this directly

Calls 9

ForHTTPFunction · 0.92
PrintfFunction · 0.92
WithExposedPortsFunction · 0.85
WithWaitStrategyFunction · 0.85
TerminateContainerFunction · 0.85
RunFunction · 0.70
HostMethod · 0.65
StateMethod · 0.65
WithStartupTimeoutMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…