diff --git a/docs/features/common_functional_options.md b/docs/features/common_functional_options.md index 928c451217..9a7e459dd8 100644 --- a/docs/features/common_functional_options.md +++ b/docs/features/common_functional_options.md @@ -437,6 +437,13 @@ ctr, err := mymodule.Run(ctx, "docker.io/myservice:1.2.3", If you need to prevent the container from being started after creation, you can use the `testcontainers.WithNoStart` option. +##### WithProvider + +- Not available until the next release :material-tag: main + +If you need specify which provider to use to run the container, you can use the `testcontainers.WithProvider` option. +Currently only `docker` or `podman` are supported. + #### Experimental Options ##### WithReuseByName diff --git a/docs/features/common_functional_options_list.md b/docs/features/common_functional_options_list.md index 119ad636b6..cb8e173d85 100644 --- a/docs/features/common_functional_options_list.md +++ b/docs/features/common_functional_options_list.md @@ -60,6 +60,8 @@ The following options are exposed by the `testcontainers` package. - [`CustomizeRequest`](/features/creating_container/#customizerequest) Since :material-tag: v0.20.0 - [`WithName`](/features/creating_container/#withname) Since :material-tag: v0.38.0 - [`WithNoStart`](/features/creating_container/#withnostart) Since :material-tag: v0.38.0 +- [`WithProvider`](/features/creating_container/#withprovider) Not available until the next release :material-tag: main + ### Experimental Options diff --git a/docs/system_requirements/using_podman.md b/docs/system_requirements/using_podman.md index 4143306901..a9692d39b7 100644 --- a/docs/system_requirements/using_podman.md +++ b/docs/system_requirements/using_podman.md @@ -44,6 +44,44 @@ The reaper container needs to connect to the docker daemon to reap containers, s > systemctl --user start podman.socket ``` +## MacOS + +Currently, in MacOS the autodetection of podman does not work as intended, which leads to Ryuk failing at boot-up. +In order to use Testcontainers then either +1. Disable Ryuk (not recommended): see [here](../features/garbage_collector.md#ryuk) +2. If you want to use Ryuk then you need + 1. Run podman in rootful mode by running the following commands + ```bash + podman machine stop + podman machine set --rootful + podman machine start + ``` + 2. Add + ``` + ryuk.container.privileged=true + ``` + to `~/.testcontainers.properties` + 3. Use the `WithProvider` option when running your containers + ```go + package some_test + + import ( + "testing" + + tc "github.com/testcontainers/testcontainers-go" + ) + + func TestSomething(t *testing.T) { + ctx := t.Context() + ctr, err := tc.Run(ctx, + "docker.io/myservice:1.2.3", + tc.WithProvider(tc.ProviderPodman), + ) + + // ... + } + ``` + ## Fedora `DOCKER_HOST` environment variable must be set diff --git a/options.go b/options.go index f7775f8665..a930c54104 100644 --- a/options.go +++ b/options.go @@ -537,3 +537,12 @@ func WithFiles(files ...ContainerFile) CustomizeRequestOption { return nil } } + +// WithProvider sets the provider type for a container +func WithProvider(provider ProviderType) CustomizeRequestOption { + return func(req *GenericContainerRequest) error { + req.ProviderType = provider + + return nil + } +} diff --git a/options_test.go b/options_test.go index 4e7864a5b0..8e58946f68 100644 --- a/options_test.go +++ b/options_test.go @@ -906,3 +906,30 @@ func TestWithWaitStrategy(t *testing.T) { }) }) } + +func TestWithProvider(t *testing.T) { + t.Parallel() + req := testcontainers.GenericContainerRequest{ + ContainerRequest: testcontainers.ContainerRequest{ + Image: "alpine", + }, + } + + t.Run("default", func(t *testing.T) { + opt := testcontainers.WithProvider(testcontainers.ProviderDefault) + require.NoError(t, opt.Customize(&req)) + require.Equal(t, testcontainers.ProviderDefault, req.ProviderType) + }) + + t.Run("docker", func(t *testing.T) { + opt := testcontainers.WithProvider(testcontainers.ProviderDocker) + require.NoError(t, opt.Customize(&req)) + require.Equal(t, testcontainers.ProviderDocker, req.ProviderType) + }) + + t.Run("podman", func(t *testing.T) { + opt := testcontainers.WithProvider(testcontainers.ProviderPodman) + require.NoError(t, opt.Customize(&req)) + require.Equal(t, testcontainers.ProviderPodman, req.ProviderType) + }) +}