-
Notifications
You must be signed in to change notification settings - Fork 142
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
Unable to use exposed port #750
Comments
Alright, I preliminarily dismissed that I am running Podman, not Docker. As it turns out, this error is related to Podman. With the following code, I am viewing the network settings of the container. use testcontainers::{
core::{IntoContainerPort, WaitFor},
core::client,
runners::AsyncRunner,
GenericImage,
};
#[tokio::main]
async fn main() {
let container = GenericImage::new("redis", "7.2.4")
.with_exposed_port(6379.tcp())
.with_wait_for(WaitFor::message_on_stdout("Ready to accept connections"))
.start()
.await
.unwrap();
let docker = client::docker_client_instance().await.unwrap();
let id = container.id();
let ports = docker
.inspect_container(id, None)
.await
.unwrap()
.network_settings
.unwrap_or_default()
.ports;
// .map(Ports::try_from)
// .transpose()?
// .unwrap_or_default();
println!("{:?}", ports);
let host = container.get_host().await.unwrap();
let port = container.get_host_port_ipv4(6379).await.unwrap();
let url = format!("redis://{host}:{port}");
println!("Redis is running on {}", url);
} Here is the output with Podman (Fedora 41):
And here is the output with Docker (Ubuntu 24.04.1 + Docker 24.0.7 from App Center):
To spell it out, the I will try to figure out why that is and what can be done about this. The code responsible for extracting port and host information is in |
One can get the list of running containers with this:
Port mapping output from Podman:
Here the output with Docker:
|
Here is the official API documentation: https://docs.docker.com/reference/api/engine/version/v1.47/#tag/Container/operation/ContainerInspect The description of
As shown in the previous comment,
Does Podman follow this definition? I am not sure. Shall testcontainers-rs have a workaround for Podman? I will now look into other implementations of testcontainers to see if and how they account for the output Podman is providing. |
In The following issue suggests that the intention of Docker is to map an exposed port to the same port on both, IPv4 and IPv6: moby/moby#42442 |
That's a good research, thank you! I think we need to improve the experience with podman. Also, Testonctiners usually have separate guide for alternative engines, e.g Go version. We need to improve our documentation |
My temporal workaround is the following modification.
I will try to come up with a good solution to this problem. Assuming that there are or will be more situations where workarounds for Podman are required, I would like to find a method to detect if Podman or Docker is used, then switch on that outcome. |
Personally, I find the differentiation useful, it provides better control IMO. But we can try to find a compromise |
As a continuation of #749, I am trying to get a very simple example working. Unfortunately, I seem to be misusing the functions and am unable to figure out how to expose a port and then access the exposed port.
This is the example I am trying to make work. It is based on the example from the Quickstart.
Unfortunately, it does not work.
How can a port be exposed and then used?
The text was updated successfully, but these errors were encountered: