1 year ago
#381041
tomi
Testcontainers: Can't get Docker image
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?
java
spring
docker
junit
testcontainers
0 Answers
Your Answer