-
Notifications
You must be signed in to change notification settings - Fork 298
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
Bug: Running Container with_network makes get_exposed_port unreliable #633
Comments
Can achieve the desired result by passing network=network.name and desired hostname as kwargs when creating the container. I am still unsure how and why it is so unstable when using the with_network, and also if this maybe should be removed. With reference to pass in on the initializer instead |
@alexanderankin saw you added some labels. I am happy to assist! |
I have introduced this pattern for configurations which are experimental testcontainers-python/core/testcontainers/core/config.py Lines 65 to 66 in 41fbdd0
if we can add something like this which links to this exact issue that would be great. what would be even better is identifying and resolving the issue, which i believe stems from faulty detection with regards to detecting whether or not we are inside of a nested containerized situation or not (or reacting to that correctly). I would say it is certainly not deprecated for removal, I think we should try to fix it first before giving up entirely. |
lets not add container arguments - generally there is nothing magic going on here - maybe I can discover something after taking a closer look - if it works in the contstructor but not in the with_network should maybe even be an easy fix |
Understood! Thanks |
For people stumbling here and for which the workaround is not clear, here it is: from testcontainers.core.container import DockerContainer
from testcontainers.core.network import Network
network = Network()
network_name = network.name
networking_config = {network_name: {"aliases": ["my-service-alias-1", "my-service-alias-2"]}
container = DockerContainer("your-image-name", network=docker_network.name, networking_config=networking_config)
container.start()
...
container.stop() By the way, I'm wondering if the |
anyone care to weigh in if #678 fixes things? went out in 4.8.0 today |
Hi @alexanderankin , I'm using 4.8.1 and having the same issue. This is my code: async def init_db(
postgres_ro: PostgresContainer,
):
print(postgres_ro.get_connection_url()) # outputs correctly
print(postgres_ro.port) # prints the inner port 5321
print(postgres_ro.ports) # prints {5321: None}
print(postgres_ro.get_exposed_port(5321)) # hangs and crashes it looks like the only way to connect to the container would be to use the entire connection url or parse the exposed port from it like in my case where i need to explicitly give a port in my connect to db function |
Describe the bug
Hello!
I have a case where I want to run several containers inside a specific docker network environment.
However when attaching a container to a network it seems that port forwarding is not attached to the new network - making the overall experience unstable(not able to get postgres URL, few containers like Minio do healthcheck that hangs etc)
It seems like this is not always the case however. Roughly 30% of the times the ports are actually forwarded and it succeeded. However most of the time it fails: resulting in hanging operations etc.
To Reproduce
Given a case as below. Keep in mind that sometimes it does work. Most of the time it won't.
Result will be that get_exposed_port operation hangs
Runtime environment
Provide a summary of your runtime environment. Which operating system, python version, and docker version are you using? What is the version of
testcontainers-python
you are using? You can run the following commands to get the relevant information.The text was updated successfully, but these errors were encountered: