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

Is there a way to set the memory capacity for a GenericContainer? #298

Closed
macks22 opened this issue Feb 24, 2017 · 11 comments
Closed

Is there a way to set the memory capacity for a GenericContainer? #298

macks22 opened this issue Feb 24, 2017 · 11 comments
Assignees
Milestone

Comments

@macks22
Copy link

macks22 commented Feb 24, 2017

I have the following GenericContainer:

/**
 * A docker container that can be used with an @ClassRule to start the container before
 * and tear it down after a test class. This container exposes port 9200 as 9201 and port 9300 as 9301.
 * It also copies over the elasticsearch.yml file from the test resources.
 */
public class ElasticsearchTestContainer extends GenericContainer {

    private static final ImageFromDockerfile IMAGE_FROM_DOCKERFILE =
            new ImageFromDockerfile("test-es-image", false)
                    .withDockerfileFromBuilder(builder -> builder
                            .from("elasticsearch:2.2")
                            .run("/usr/share/elasticsearch/bin/plugin install analysis-icu")
                            .run("/usr/share/elasticsearch/bin/plugin install delete-by-query")
                            .copy("elasticsearch.yml", "/usr/share/elasticsearch/config/elasticsearch.yml")
                            .build()
                    ).withFileFromClasspath("elasticsearch.yml", "docker/elasticsearch.yml");

    public ElasticsearchTestContainer() {
        super(IMAGE_FROM_DOCKERFILE);
        this.setPortBindings(Arrays.asList("9201:9200", "9301:9300"));
        this.setNetworkMode("devhost.hostname.com");
        this.setWaitStrategy(Wait.forHttp("/"));
    }
}

Normally, I would specify the memory using the -m flag to docker. How can I do this with this container?

@kiview
Copy link
Member

kiview commented Feb 24, 2017

So you want to set a memory limit? AFAIK testcontainers doesn't expose an API for this yet.

I also only found a fitting API in docker-java inside the UpdateContainerCmd class, not inside CreateContainerCmd.

@benhinssen
Copy link

+1
I was also looking for this feature.

@kiview
Copy link
Member

kiview commented Mar 1, 2017

@benhinssen could you please give some context for use cases for which this feature is needed?

@rnorth
Copy link
Member

rnorth commented Mar 1, 2017

It looks like it's there on CreateContainerCmd. It's worth supporting, but we might be opening a can of worms if we add this directly to the GenericContainer API.

Perhaps the more maintainable approach is to use some upcoming preconfig/postconfig hooks that @bsideup was working on that allow you to modify the CreateContainerCmd directly before it's created. How does that sound?

@bsideup
Copy link
Member

bsideup commented Mar 1, 2017

+1 from me on hooks :)

Something like:

new GenericContainer(...)
    .withCreateCmdHook(cmd -> cmd.withMemory(1024))

(naming is not final)

@benhinssen
Copy link

@kiview of course.
In our development build, we use testcontainers to simulate our production environment to run E2E tests. So during our build testcontainers spins up about 10 docker images that must be tested together.

At this moment we are having some problems that our build server is running out of resources when running multiple builds simultaneously. The obvious way to prevent this from happening is to limit the max resources that can be used by each docker container.
We have all the docker images that are being started on our build server limited, except the ones the are spun up by testcontainers. We can also limit it using parameter of the java process inside the docker testcontainer, but it would be nice to be able to limit cpu usage when starting the container.

@bsideup bsideup added this to the 1.1.10 milestone Mar 1, 2017
@bsideup bsideup self-assigned this Mar 1, 2017
@bsideup
Copy link
Member

bsideup commented Mar 1, 2017

See #301

@bsideup
Copy link
Member

bsideup commented Mar 13, 2017

@macks22 @benhinssen since 1.2.0 is out, does https://www.testcontainers.org/usage/options.html#customizing-the-container sound good enough for you? :)

@macks22
Copy link
Author

macks22 commented Mar 13, 2017

@bsideup yes this meets the need; thank you! @benhinssen feel free to close if your use case is satisfied.

@benhinssen
Copy link

benhinssen commented Mar 13, 2017

Looks good and fits the requirement! Thanks!
@macks22, for me you can close the issue, it seems as I can't as I did not open the issue.

@rnorth
Copy link
Member

rnorth commented Mar 13, 2017

Great, thanks @benhinssen, @macks22!

I'll close the ticket then 😄

@rnorth rnorth closed this as completed Mar 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants