Docker Community Forums

Share and learn in the Docker community.

How to redirect the localhost of container to host localhost

I have hosted an apllication in docker container using windows docker desktop. i can see its getting hosted inside the container rather than in hosts localhost.

tried multiple solution available over internet but nothing worked out.

1.Used -p to publish to redirect the port.
2.Used --network="host" in your docker run command
3.tried export DOCKER_HOST_IP=$(route -n | awk ‘/UG[ \t]/{print $2}’)

root@0be0501ec1aa:/streetscape# netstat -ap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 localhost:http-alt* LISTEN 677/node
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node PID/Program name Path
root@0be0501ec1aa:/streetscape# curl http://localhost:8080
<!doctype html> quick start body { margin: 0; } #container { position: fixed; display: flex; width: 100vw; height: 100vh; overflow: hidden; } #control-panel { box-sizing: border-box; width: 320px; padding: 12px; position: relative; z-index: 1; box-shadow: 0 0 8px rgba(0,0,0,0.3); height: 100%; overflow-x: hidden; overflow-y: auto; } #control-panel hr { margin: 24px -12px; opacity: 0.3; } #log-panel { flex-grow: 1; display: flex; flex-direction: column; height: 100%; } #map-view { flex-grow: 1; position: relative; } #timeline { padding: 24px 0; position: relative; } #hud { position: absolute; top: 12px; right: 12px; display: flex; flex-direction: column; box-shadow: 0 0 8px rgba(0,0,0,0.3); } #hud hr {margin: 0; opacity: 0.3;}

You want to publish the exposed port to the outside world. Use a flag on the run command -p 8080:8080 to link the container’s port 8080 to the host port 8080. It goes in this order -p [HOST]:[CONTAINER]. You can add multiple -p options and the host port needs to not be in use by something else. If you are orchestrating multiple containers with docker-compose.yml file then add the follow.
- “8080:8080”