Starbucks Admin
Starbucks Admin

Reputation: 937

cannot get docker image while using TestContainer

I am having a junit test written using test container (https://www.testcontainers.org/). when I run my test I get the following stack trace.

com.github.dockerjava.api.exception.UnauthorizedException: Status 401: {"message":"Get https://registry-1.docker.io/v2/testcontainers/ryuk/manifests/0.3.1: unauthorized: incorrect username or password"}

    at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:239)
    at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.lambda$executeAndStream$1(DefaultInvocationBuilder.java:269)
    at java.lang.Thread.run(Thread.java:748)

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 6.797 sec <<< FAILURE! - in com.openmind.primecast.web.rest.MessageHistoryReportingResourceIntTest
com.openmind.primecast.web.rest.MessageHistoryReportingResourceIntTest  Time elapsed: 6.796 sec  <<< ERROR!
org.testcontainers.containers.ContainerFetchException: Can't get Docker image: RemoteDockerImage(imageName=docker.elastic.co/elasticsearch/elasticsearch:7.11.2, imagePullPolicy=DefaultPullPolicy())
    at org.testcontainers.containers.GenericContainer.getDockerImageName(GenericContainer.java:1286)
    at org.testcontainers.containers.GenericContainer.logger(GenericContainer.java:615)
    at org.testcontainers.elasticsearch.ElasticsearchContainer.<init>(ElasticsearchContainer.java:73)
    at com.openmind.primecast.web.rest.MessageHistoryReportingResourceIntTest.startElasticServer(MessageHistoryReportingResourceIntTest.java:132)
Caused by: com.github.dockerjava.api.exception.UnauthorizedException: Status 401: {"message":"Get https://registry-1.docker.io/v2/testcontainers/ryuk/manifests/0.3.1: unauthorized: incorrect username or password"}

    at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:239)
    at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.lambda$executeAndStream$1(DefaultInvocationBuilder.java:269)
    at java.lang.Thread.run(Thread.java:748)

2021-03-24 20:30:31.584  WARN   --- [r1-nio-worker-1] io.netty.channel.DefaultChannelPipeline  : An exception '{}' [enable DEBUG level for full stacktrace] was thrown by a user handler's exceptionCaught() method while handling the following exception:

This is the code in the my junit test . Basically its trying to download elastic search docker image with version 7.11.2 . However i am unable to do so and an error is thrown on the console when i run my junit test.

public class MessageHistoryReportingResourceIntTest extends AbstractCassandraTest {

    /**
     * Elasticsearch version which should be used for the Tests
     */
    private static final String ELASTICSEARCH_VERSION = "7.11.2";

    private static final DockerImageName ELASTICSEARCH_IMAGE = DockerImageName
            .parse("docker.elastic.co/elasticsearch/elasticsearch").withTag(ELASTICSEARCH_VERSION);

    @BeforeClass
    public static void startElasticServer() throws Exception {
    container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE);
        container.start();
   }
}

this is my docker version

-bash-4.2$ docker --version
Docker version 17.03.1-ce_omn3, build 9b1cd46

in the pom.xml i have added the library

    <dependency>
        <groupId>org.testcontainers</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>1.15.2</version>
        <scope>test</scope>
    </dependency>

appreciate if you can help thank you

Upvotes: 3

Views: 4195

Answers (1)

Tamaki Sakura
Tamaki Sakura

Reputation: 520

Apparently in https://github.com/testcontainers/testcontainers-java/issues/5121#issuecomment-1102909375 they suggested the following:

docker login index.docker.io

which fix my problem

Upvotes: 1

Related Questions