Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for transparently using local images with docker-compose #798

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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