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

Use of links between containers should be deprecated #465

Open rnorth opened 6 years ago

rnorth commented 6 years ago

As discussed in #463, docker networks seem mature enough to use, and links are officially not recommended any more.

We'd like to deprecate use of links; off the top of my head I believe we ought to do the following things:

kiview commented 6 years ago

I'm really looking forward to removing the ambassador container, I believe this will make things a lot easier in more complex CI environments.

kiview commented 6 years ago

AFAIK the only thing missing now is the documentation update?

felixbarny commented 6 years ago

I'd very much appreciate some docs around networks :)

kiview commented 6 years ago

@felixbarny Yep you are right, PR appreciated :smile_cat:

bsideup commented 6 years ago

@felixbarny yes, the docs are missing and I feel sorry about it (since I was the one who implemented the networks support) However, it is as simple as .withNetwork(networkInstance) and until it is implemented you an check existing usages in tests, i.e. Kafka: https://github.com/testcontainers/testcontainers-java/blob/b5181f784c63b91a61ec68cd58acc522ce4d2dbc/modules/kafka/src/test/java/org/testcontainers/containers/KafkaContainerTest.java#L52-L69

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.

stale[bot] commented 5 years ago

This issue has been automatically closed due to inactivity. We apologise if this is still an active problem for you, and would ask you to re-open the issue if this is the case.

rnorth commented 5 years ago

Reopening - docs still needed

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.

bsideup commented 4 years ago

@rnorth given https://www.testcontainers.org/features/networking/#advanced-networking, should we close the issue now? :)

sunmeplz commented 1 year ago

Hi there, Sometimes it is not possible to add network to container as it managed with third party libs, so add-link is the single solution

eddumelendez commented 1 year ago

if it is built with GenericContainer similar to the Testcontainers modules then you should have access to withNetwork. Can you elaborate @sunmeplz , please?

sunmeplz commented 1 year ago

Hi @eddumelendez ! My case: I'm using quarkus framework which provide dev services based on test containers(https://github.com/quarkusio/quarkus/blob/main/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java). When you run application in dev or test mode, quarkus run the container. My goal is to create additional service which will use existing container(kafka and db in my case). So I can't access testcontainer instance, just can find already running container using plain docker api

jfrantzius commented 9 months ago

Hi, the task "Modify Docker Compose support; can we remove use of the ambassador container now?" that is listed as completed in the description is unfortunately blocking https://github.com/testcontainers/testcontainers-java/issues/5351 , please see comment https://github.com/testcontainers/testcontainers-java/issues/5351#issuecomment-1838847583 there for details.

Are there any plans to replace the deprecated call to SocatContainer.addLink() in ComposeDelegate.withExposedService(String, int, WaitStrategy) with network API calls, as Testcontainer's own Javadoc suggests? https://javadoc.io/doc/org.testcontainers/testcontainers/latest/index.html :

@Deprecated public void addLink(LinkableContainer otherContainer, java.lang.String alias) Deprecated. Links are deprecated (see #465). Please use Network features instead. Description copied from interface: Container Add a link to another container.

kiview commented 9 months ago

Thanks for collecting the references @jfrantzius. I am not sure why the compose task in the original post in this issue is marked as done, since it is not yet done. I think it makes much sense to re-visist this, ideally with a non-breaking change that provides better compatibility within the ecosystem.

That being said, there aren't concrete plans to tackle this yet (although AFAIK @eddumelendez did a spike on this in the past).