Binding Established Address to Localhost in Docker-Compose

I still don’t understand it. The netstat output you shared shows that the process is listening on the container’s ip address, not on localhost and the fact that you can access it from another container proves that it is accssible from other IPs. The answer @bluepuma gave you was correct based on what you shared. That forwards all requests from localhost:8020 to the container’s ip address on which the process is listening.

Please, show your compose file with your portmapping, because I suspect you just addedd the mapping to a wrong place in the file. Or you were not able to explain what you actually want to achieve. For example this doesn’t make sense to me:

You have a process listening on a port in the container. You can forward requests from your host to the container but you don’t need to forward it to localhost again. The process already got the request. Unless you meant the opposite and you want to forward a port inside the container to the host outside the container.

The part of the above sentence in the parenthesis and outside are contradict each other. It’s either you make a container port acesible from the host outside the container or let a process (datanode) inside the container to access a port on the host.

If port 8020 is on which the datanode is listening than the port has nothing to do with how it can access ports on the host. You can use host.docker.internal hostname in Docker Desktop to access something on the physical host outside the container or do something similar without Docker Desktop on Linux: