Testcontainers:无法获取 Docker 映像
我正在尝试使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论