testcontainers / testcontainers-java

Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
https://testcontainers.org
MIT License
8.01k stars 1.65k forks source link

Creating Testcontainer from custom image doesn't work #831

Open jo2 opened 6 years ago

jo2 commented 6 years ago

I'm writing tests for my room-service and i need the image-service because the room-service has dependencies on the image-service. this is my file tree:

+---image-service
¦   ¦   Dockerfile
¦   ¦   pom.xml
¦   ¦
¦   +---src
¦   ¦   +---main
¦   ¦   ¦   +---java
¦   ¦   ¦   +---resources
¦   ¦   +---test
¦   ¦       +---java
¦   ¦           +---de
¦   ¦               +---fh
¦   ¦                       ApplicationTest.java
+---room-service
¦   ¦   Dockerfile
¦   ¦   pom.xml
¦   ¦
¦   +---src
¦   ¦   +---main
¦   ¦   ¦   +---java
¦   ¦   ¦   +---resources
¦   ¦   +---test
¦   ¦       +---java
¦   ¦       ¦   +---de.fh
¦   ¦       ¦           ApplicationTest.java
¦   ¦       ¦
¦   ¦       +---resources
¦   ¦               application.yml

In my ApplicationTest in room-service I try to create a generic container from the dockerfile in /image-service/Dockerfile:

@BeforeClass
public static void init() {
    eurekaContainer = new GenericContainer(new ImageFromDockerfile("image-service")
            .withFileFromFile("./image-service", new File("../image-service/Dockerfile")));

    eurekaContainer.start();
}

I couldn't find any use cases like this in the documentation. Am I using the wrong method? Are any of the paths I used wrong?

kiview commented 6 years ago

Hi @jo2,

can you try out the other methods, such as from string and from classpath?

jo2 commented 5 years ago

With imageFromString I didn´t know what I should write in the string. Is it the content of the Dockerfile? The documentation only said '.withFileFromString("folder/someFile.txt", "hello")'. Also the declaration of the method doesn´t say anything 'withFileFromString(String path, String content)'.

imageFromClasspath isn´t explained in any better way.

kgupta26 commented 3 years ago

I am currently using withDockerfile method.