Closed VladasZ closed 1 month ago
Hi @VladasZ 👋
You're looking for mapped port
Image
itself can't be sticked to particular host port, but you can run it with the mapping (just like with docker)
Additionally, depending on your use case, you may not need port mapping.
Instead, you can get the host port used for a specific exposed port using get_host_port_ipv4 of already started container.
This way, you can start multiple containers(with the same image) simultaneously
Hi @DDtKey Yeah this is exactly what I was looking for. Thank you very much!
I understand advantages of mapping containers to different ports and I already used get_host_port_ipv4
in some of my tests.
But in other test I needed to map to default Postgres
port and with_mapped_port
works perfectly for this.
If I understand correctly currently
expose_ports
method ofImage
trait allows users to specify only container port. For host port it automatically assigns some temporary port starting from 55000. But how do I specify both container and host ports like I do it indocker
cli with-p 5432:5432
argument?