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
7.98k stars 1.64k forks source link

Can't define a specific build stage for a ImageFromDockerfile #886

Open NotBad4U opened 6 years ago

NotBad4U commented 6 years ago

Hello, I'm using a container build from a Dockerfile with a multi-stage builds in my test:

public class SozuContainer <SELF extends SozuContainer<SELF>> extends GenericContainer<SELF> {
    public SozuContainer() {
        super(
            new ImageFromDockerfile()
                .withFileFromClasspath("Dockerfile", "sozu/Dockerfile")
        );
....
}     

And when I run my Junit test, the image build is the first stage of my multi-stage builds: builder. Do you have a way to declare which target stage I want for my ImageFromDockerfile ?

kiview commented 6 years ago

Hi @NotBad4U, thanks for your feedback. This is probably a missing feature in docker-java, since we delegate the build to BuildImageCmd.

rnorth commented 5 years ago

Just to add an update: I considered adding this in #1372 but this remains something that we'd need to add to docker-java first.

trajano commented 2 years ago

Is there a workaround for this one? Like using docker-compose instead? Also seems like target support was added already to docker java https://github.com/docker-java/docker-java/issues/1113

eddumelendez commented 1 year ago

@trajano you can do something like this

static class CustomImageFromDockerfile extends ImageFromDockerfile {

    @Override
    protected void configure(BuildImageCmd buildImageCmd) {
        super.configure(buildImageCmd);

        buildImageCmd.withTarget("builder");
    }
}

and then call new CustomImageFromDockerfile().withDockerfile(Paths.get("src/test/resources/Dockerfile-multistage"))