So I tried to switch the concept around, like you suggest, where I do the bind inside the container, effectively switching the concept of server and client. All goes well inside the container.
But then, when I try to write a program host-side, effectively acting as a client, this doesn’t work since: because I have nothing to bind to, there is no host:port combo for me to read data from.
The whole point of my design is so that my program, running inside the container, can write data to a port that an end-user can connect to to read the data from.
When I do this directly on a machine, this works. When I dockerize the client-side, it no longer works since now I can’t bind to the port host-side since the docker-proxy has already done the bind itself to expose the port from inside the container to the host.
I am coming to the conclusion that this is an unintended consequence of port forwarding in Docker and that this is not possible.
But shouldn’t it be?