Comments (5)
Hi Jan,
Thanks for this - that's a good point. I'm wondering, since the port availability wait can tend to be quite important, if there might be another option.. How about an environment variable that would be able to override the container address detection?
e.g. in DockerClientFactory.instance().dockerHostIpAddress()
:
if using /var/run/docker.sock, container address = 'localhost' unless TESTCONTAINERS_CONTAINER_HOST
is set, in which case return the value of that
That way the wait-for-start behaviour can carry on working (using getContainerIpAddress()
), plus tests can remain independent (calling getContainerIpAddress()
themselves).
Would that help in your case?
Thanks
Richard
from testcontainers-java.
That sounds like it would solve the problem. However I tend to like properties more than environment variables. This way it's easier to integrate with Jenkins and Maven, e. g. I can run a build like
mvn clean install -Dtestcontainers.container.host=docker-machine-ip
And it doesn't pollute the build server's environment.
If such a feature is going to be integrated it may be a good idea to mark it as experimental for some time since I am not exactly sure if it does really make sense that way. I mean: If it wasn't for the docker in docker setup, then socket->localhost, ip->someOtherHost holds true und is perfectly reasonable. The new feature may cause things to become more complicated (also more powerful) and it must be seen if similar situations do exist where it comes in handy. Maybe provisioning Jenkins Slaves with Docker or running a whole container as test would be another use case for this.
from testcontainers-java.
Yes, I think I'd probably want an equivalent system property for any environment variable setting anyway, so that would be OK.
I do think it is worth thinking more about where this would be useful, as you suggest. Another scenario I can imagine that might need something similar would be use of Docker Swarm. In that case the env var/property would be too simplistic to relate to where the container actually ends up. So maybe something programmatic might be a better idea - at least gives users the option of implementing more sophisticated behaviour when it's genuinely needed...
I'll have a bit more of a think about it and maybe propose some other approaches tomorrow.
Thanks for your input!
Richard
from testcontainers-java.
I'm thinking I'll keep this reasonably simple for now:
- if env var
TESTCONTAINERS_CONTAINER_HOST
or sysproptestcontainers.container.host
is set, that value will always be returned fromgetContainerIpAddress()
(no matter what) - otherwise the usual logic will apply - it will return the
DOCKER_HOST
address unless using a unix socket, in which case it will return localhost
I think this gives necessary flexibility without complicating things too much...
This doesn't cater for the swarm example, but in such a scenario getContainerIpAddress()
is unlikely to be useful anyway - there's only so much it can do. Instead some other project/environment specific method should be written separately and used in its place, outside of the testcontainers library.
I'll set this up in a branch for review.
from testcontainers-java.
Closing this in conjunction with PR #92 for the time being.
from testcontainers-java.
Related Issues (20)
- [Bug]: Many custom variables do not take effect when using custom configurations HOT 1
- [Bug]: JDBC host-less URI (///) are not parsed correctly
- [Feature]: Add consumer for logging into file
- [Bug]: Containers not shut down between tests when using .withReuse(true) but env. does not support reuse HOT 2
- [Bug]: CosmosDBEmulatorContainer 'EOFException: SSL peer shut down incorrectly' when building keystore HOT 3
- [Bug]: Vulnerable dependency commons-compress 1.24.0 HOT 3
- [Enhancement]: Add OpenFGAContainer
- [Bug]: Building a container when running inside another one with mounted socket is not possible
- [Feature]: Document and provide tooling for running testcontainers from windows (ie: intellij) using docker ce on wsl without desktop
- [Enhancement]: use official kafka image HOT 3
- [Enhancement]: clickhouse should be supported by r2dbc
- [Enhancement]: Proposal to Upgrade Alpine Version in DockerClientFactory.java due to Impending EOL
- [Bug]: Cannot run redpanda testcontainer with podman HOT 1
- [Bug]: Can't connect to Ryuk possibly due to some strange docker network interaction.
- [Bug]: Unexpected exit of vnc-recorder when closing pop-ups on MacOS
- [Bug]: Docker Image Pulls Have No Interval between failed attempts
- [Bug]: DockerComposeContainer: Stop exception when variable substitution is used in compose file HOT 1
- [Enhancement]: Support new Weaviate container registry
- [Enhancement]: Support TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE to be read from ~/.testcontainers.properties
- [Bug]: Race condition between DB init and test executions from JdbcDatabaseContainer based containers HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testcontainers-java.