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

Start container with hostname #311

Closed
rahul-swaminathan opened this issue Mar 9, 2017 · 13 comments
Closed

Start container with hostname #311

rahul-swaminathan opened this issue Mar 9, 2017 · 13 comments
Milestone

Comments

@rahul-swaminathan
Copy link

We are using GenericContainer and we need to set a specific hostname for our container. Right now, we are using withExtraHosts and hardcoding the ip address that the container always starts with. This creates 2 entries in /etc/hosts with the same ip address. We'd rather have a function withHostName that leverages

dockerClient.createContainerCmd().withHostName
@rnorth
Copy link
Member

rnorth commented Mar 9, 2017

Hi Rahul
Thanks for using Testcontainers and for raising this - seems perfectly sensible to me and isn't a big change. We can probably do this quickly. However, if it's urgent, if you'd care to raise a PR we'd be able to include this even sooner!
Thanks
Richard

@bsideup
Copy link
Member

bsideup commented Mar 10, 2017

FYI this PR will make it possible to configure hostname manually:
#301

@rnorth
Copy link
Member

rnorth commented Mar 10, 2017

@bsideup yes, you're right!

@rahul-swaminathan
Copy link
Author

awesome, thanks!

@rnorth rnorth added this to the 1.2.0 milestone Mar 12, 2017
@bsideup
Copy link
Member

bsideup commented Mar 13, 2017

@rahul-swaminathan version 1.2.0 was released, you can find how to tune CreateContainerCmd in the docs now:
https://www.testcontainers.org/usage/options.html#customizing-the-container

Do you still want it implemented as container.withHostName()? If not, I assume we can close this issue for now :)

@edgarvonk
Copy link

Hi all, the CreateContainerCmd works fine with the GenericContainer (in our case we use it to set the name of the container upon creation). However I think it is not supported for the JdbcDatabaseContainers? We would like to use the CreateContainerCmd with e.g. the OracleContainer.

@edgarvonk
Copy link

Ah sorry, it is possible with a JdbcDatabaseContainer as well. Just a little bit more cumbersome. E.g.:

   @ClassRule
    public static GenericContainer oracleContainer = new OracleContainer()
        .withCreateContainerCmdModifier((Object createContainerCmd) -> {
            ((CreateContainerCmd)createContainerCmd).withName("oracle");
        });

@bsideup
Copy link
Member

bsideup commented Mar 30, 2017

@edgarvonk

or

    @ClassRule
    public static GenericContainer oracleContainer = new OracleContainer<>()
        .withCreateContainerCmdModifier(it -> it.withName("oracle"));

(note the diamond <> )

@edgarvonk
Copy link

Hi @bsideup, I did try that but that is not possible because OracleContainer is not a parameterised type (in contrast to GenericContainer)? This code does not compile for me anyway.

@bsideup
Copy link
Member

bsideup commented Mar 30, 2017

@edgarvonk,

hm-hm... Does it happen if you change GenericContainer oracleContainer to OracleContainer oracleContainer? without <>

Sorry for that anyway, we're going to polish generics in 2.0

@edgarvonk
Copy link

hi @bsideup, no it happens regardless of whether I use GenericContainer or OracleContainer as the variable type.

No problem at all!

@rahul-swaminathan
Copy link
Author

@bsideup yup, we switched over to using withCreateContainerCmdModifier and everything works great, thanks!

@bsideup
Copy link
Member

bsideup commented Apr 5, 2017

Awesome! I'm closing the issue :)

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

No branches or pull requests

4 participants