Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 726
deamon Avatar asked May 29 '18 12:05

deamon


People also ask

Can Kubernetes use local Docker image?

Kubernetes use local docker image is nothing but create Kubernetes image locally and deploy the same on Kubernetes cluster locally; the first step is to deploy our application on Kubernetes to build the docker image. Next, we need to use minikube to run the Kubernetes in our local environment.

Do I need Docker to run Testcontainers?

In order to use Testcontainers in a Gitlab CI pipeline, you need to run the job as a Docker container (see Patterns for running inside Docker).

Where should Testcontainers properties be placed?

The classpath testcontainers. properties file may exist within the local codebase (e.g. within the src/test/resources directory) or within library dependencies that you may have. Any such configuration files will have their contents merged.


1 Answers

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

If you are 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.

like image 151
Elizaveta Kuznetsova Avatar answered Oct 27 '22 23:10

Elizaveta Kuznetsova