github.com/goravel/framework@v1.13.9/support/docker/docker.go (about)

     1  package docker
     2  
     3  import (
     4  	"github.com/ory/dockertest/v3"
     5  	"github.com/ory/dockertest/v3/docker"
     6  	"github.com/pkg/errors"
     7  )
     8  
     9  func Pool() (*dockertest.Pool, error) {
    10  	pool, err := dockertest.NewPool("")
    11  	if err != nil {
    12  		return nil, errors.WithMessage(err, "Could not construct pool")
    13  	}
    14  
    15  	if err := pool.Client.Ping(); err != nil {
    16  		return nil, errors.WithMessage(err, "Could not connect to Docker")
    17  	}
    18  
    19  	return pool, nil
    20  }
    21  
    22  func Resource(pool *dockertest.Pool, opts *dockertest.RunOptions) (*dockertest.Resource, error) {
    23  	return pool.RunWithOptions(opts, func(config *docker.HostConfig) {
    24  		// set AutoRemove to true so that stopped container goes away by itself
    25  		config.AutoRemove = true
    26  		config.RestartPolicy = docker.RestartPolicy{
    27  			Name: "no",
    28  		}
    29  	})
    30  }