Testcontainers:无法获取 Docker 映像

发布于 2025-01-19 09:28:22 字数 2332 浏览 0 评论 0原文

我正在尝试使用TestContainers编写JUNIT测试,而问题在于启动容器。这是我的测试类:

package com.example;

import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.testcontainers.containers.GenericContainer;

import static org.junit.Assert.assertEquals;

public class TestExample {

  @ClassRule
  public static GenericContainer redis = new GenericContainer("redis:3.0.6").withExposedPorts(6379);

  private RedissonClient redisson;

  @Before
  public void setup() {
    redis.start();
    final Config config = new Config();
    config.useSingleServer()
        .setAddress("redis://127.0.0.1:6379");
    this.redisson = Redisson.create(config);
  }

  @Test
  public void test() {
    redisson.getBucket("example").set("test");
    assertEquals("test", redisson.getBucket("example").get());
  }

  @After
  public void cleanup() {
    redis.stop();
  }
}

在运行测试后,发生以下例外:

org.testcontainers.containers.ContainerLaunchException: Container startup failed

    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:327)
    at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:308)

Caused by: org.testcontainers.containers.ContainerFetchException: Can't get Docker image: RemoteDockerImage(imageName=redis:3.0.6, imagePullPolicy=DefaultPullPolicy())
    at org.testcontainers.containers.GenericContainer.getDockerImageName(GenericContainer.java:1278)
    at org.testcontainers.containers.GenericContainer.logger(GenericContainer.java:612)
    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:317)
    ... 13 more
Caused by: java.util.NoSuchElementException: No value present
    at java.base/java.util.Optional.get(Optional.java:148)
    at org.testcontainers.utility.ResourceReaper.start(ResourceReaper.java:117)
    at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:203)
    at org.testcontainers.LazyDockerClient.getDockerClient(LazyDockerClient.java:14)
    at org.testcontainers.LazyDockerClient.listImagesCmd(LazyDockerClient.java:12)
    ... 15 more

我正在Fedora 31,Junit4,Java 11和TestContainers版本1.15.0上运行此测试。 关于为什么不可用的图像有什么想法?

I'm trying to write JUnit tests using testcontainers and the problem is with starting the containers. This is my test class:

package com.example;

import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.testcontainers.containers.GenericContainer;

import static org.junit.Assert.assertEquals;

public class TestExample {

  @ClassRule
  public static GenericContainer redis = new GenericContainer("redis:3.0.6").withExposedPorts(6379);

  private RedissonClient redisson;

  @Before
  public void setup() {
    redis.start();
    final Config config = new Config();
    config.useSingleServer()
        .setAddress("redis://127.0.0.1:6379");
    this.redisson = Redisson.create(config);
  }

  @Test
  public void test() {
    redisson.getBucket("example").set("test");
    assertEquals("test", redisson.getBucket("example").get());
  }

  @After
  public void cleanup() {
    redis.stop();
  }
}

After running the test the following exception occurs:

org.testcontainers.containers.ContainerLaunchException: Container startup failed

    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:327)
    at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:308)

Caused by: org.testcontainers.containers.ContainerFetchException: Can't get Docker image: RemoteDockerImage(imageName=redis:3.0.6, imagePullPolicy=DefaultPullPolicy())
    at org.testcontainers.containers.GenericContainer.getDockerImageName(GenericContainer.java:1278)
    at org.testcontainers.containers.GenericContainer.logger(GenericContainer.java:612)
    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:317)
    ... 13 more
Caused by: java.util.NoSuchElementException: No value present
    at java.base/java.util.Optional.get(Optional.java:148)
    at org.testcontainers.utility.ResourceReaper.start(ResourceReaper.java:117)
    at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:203)
    at org.testcontainers.LazyDockerClient.getDockerClient(LazyDockerClient.java:14)
    at org.testcontainers.LazyDockerClient.listImagesCmd(LazyDockerClient.java:12)
    ... 15 more

I'm running this test on Fedora 31, JUnit4, Java 11, and testcontainers version 1.15.0.
Any ideas on why is the image unavailable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文