Skip to content

Commit

Permalink
Add support for transparently using local images with docker-compose (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kiview committed Jul 26, 2018
1 parent 910aea2 commit 6217f32
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ public void start() {
synchronized (MUTEX) {
registerContainersForShutdown();
if (pull) {
pullImages();
try {
pullImages();
} catch (ContainerLaunchException e) {
logger().warn("Exception while pulling images, using local images if available", e);
}
}
applyScaling(); // scale before up, so that all scaled instances are available first for linking
createServices();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.testcontainers.junit;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.core.command.PullImageResultCallback;
import org.junit.Test;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.DockerComposeContainer;

import java.io.File;

public class DockerComposeLocalImageTest {

@Test
public void usesLocalImageEvenWhenPullFails() throws InterruptedException {
tagImage("redis:4.0.10", "redis-local", "latest");

DockerComposeContainer composeContainer = new DockerComposeContainer(new File("src/test/resources/local-compose-test.yml"))
.withExposedService("redis", 6379);
composeContainer.start();
}

private void tagImage(String sourceImage, String targetImage, String targetTag) throws InterruptedException {
DockerClient client = DockerClientFactory.instance().client();
client.pullImageCmd(sourceImage).exec(new PullImageResultCallback()).awaitCompletion();
client.tagImageCmd(sourceImage, targetImage, targetTag).exec();
}
}
6 changes: 6 additions & 0 deletions core/src/test/resources/local-compose-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '2'
services:
redis:
image: redis-local:latest
ports:
- 6379

0 comments on commit 6217f32

Please sign in to comment.