How to create a container

File

qianmoQqianmoQ· 更新于 2026-10-14· 阅读 2 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

File Wait Strategy

File Wait Strategy waits for a file to exist in the container, and allows to set the following conditions:

  • the file to wait for.
  • a matcher which reads the file content, no-op if nil or not set.
  • the startup timeout to be used in seconds, default is 60 seconds.
  • the poll interval to be used in milliseconds, default is 100 milliseconds.

Waiting for file to exist and extract the content

Waiting for file to exist and extract the content

var out bytes.Buffer
ctx := context.Background()
ctr, err := testcontainers.Run(
    ctx, "nginx:latest",
    testcontainers.WithWaitStrategy(wait.ForFile("/etc/nginx/nginx.conf").
        WithStartupTimeout(time.Second*10).
        WithPollInterval(time.Second).
        WithMatcher(func(r io.Reader) error {
            if _, err := io.Copy(&out, r); err != nil {
                return fmt.Errorf("copy: %w", err)
            }
            return nil
        }),
    ),
)

评论

登录后参与评论

正在加载评论…