deamon
deamon

Reputation: 92387

How to use local Docker image with testcontainers?

I want to use a local-only Docker image with testcontainers.

The code looks like this:

new GenericContainer("rserver:latest")...

However it looks like another image with same name is fetched from a remote registry.

How can I force testcontainers to use a local image?

Upvotes: 13

Views: 9423

Answers (1)

Elizaveta Kuznetsova
Elizaveta Kuznetsova

Reputation: 479

I know this answer is too late but it can be useful for others who has exactly the same issue.

If you already have the image you want, try to implicitly set the image Pull Policy for your container to default:

GenericContainer container = new GenericContainer("someImage")
            .withImagePullPolicy(PullPolicy.defaultPolicy());

The default image Pull Policy tells the Docker to pull the image from a remote repository only if it does not exist locally.

Note that this method (withImagePullPolicy(..)) is available only with latest versions of TestContainers dependency. I use 1.14.3.

Upvotes: 9

Related Questions