diff --git a/core/src/main/java/org/testcontainers/containers/GenericContainer.java b/core/src/main/java/org/testcontainers/containers/GenericContainer.java index 929ff41a9b4..4cae19864ea 100644 --- a/core/src/main/java/org/testcontainers/containers/GenericContainer.java +++ b/core/src/main/java/org/testcontainers/containers/GenericContainer.java @@ -267,6 +267,7 @@ public GenericContainer(@NonNull final Future image) { } public void setImage(Future image) { + this.image = new RemoteDockerImage(image); this.containerDef.setImage(new RemoteDockerImage(image)); } diff --git a/core/src/test/java/org/testcontainers/containers/GenericContainerTest.java b/core/src/test/java/org/testcontainers/containers/GenericContainerTest.java index fb0b216bce2..901f8a1eac1 100644 --- a/core/src/test/java/org/testcontainers/containers/GenericContainerTest.java +++ b/core/src/test/java/org/testcontainers/containers/GenericContainerTest.java @@ -20,6 +20,7 @@ import org.testcontainers.TestImages; import org.testcontainers.containers.startupcheck.StartupCheckStrategy; import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy; +import org.testcontainers.images.RemoteDockerImage; import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.images.builder.Transferable; import org.testcontainers.utility.MountableFile; @@ -222,6 +223,14 @@ public void testArchitectureCheck() { } } + @Test + public void shouldReturnTheProvidedImage() { + GenericContainer container = new GenericContainer(TestImages.REDIS_IMAGE); + assertThat(container.getImage().get()).isEqualTo("redis:3.0.2"); + container.setImage(new RemoteDockerImage(TestImages.ALPINE_IMAGE)); + assertThat(container.getImage().get()).isEqualTo("alpine:3.16"); + } + static class NoopStartupCheckStrategy extends StartupCheckStrategy { @Override