Docker Community Forums

Share and learn in the Docker community.

How can I navigate to container website from host browser?

I have a docker container with node and angular tools for a tutorial I’m running through. I use the angular command tools to spin up a web server within the container on port 4200. On my Windows 10 Pro host, I would like to fire up a browser and say: http://localhost:4200 so I can connect to the angular app within the container. How would I go about doing this?

This was my latest unsuccessful attempt:
docker run -it -v c:\dev:/home -p node-ng bash

When running docker container in the interactive mode (param: -it) you can get IP of the container directly in the console - ipconfig. This IP is the container IP address. Since you are running the container in Win10 and I suppose you are using default NAT adapter you cant access the container using port mapping (eg. localhost:port). The reason is WinNAT that simply doesnt work like this now. In WinServer2016 you can use this method (port mapping).

So you have to (on Win10):

  • Obtain IP of the container (ipconfig inside the container or docker inspect [containername] and search for the IP (almost in the bottom of the result).
  • Expose the port you need to access to (docker run –expose [port number]).
  • Access from you host like this: http://ip-of-your-container:port

That`s all.

Strange, this still does not work for me.

I did the following:

-docker run -it -v c:\dev:/home --expose 4200 node-ng bash
-Issued command ‘ng serve’ (from angular-cli) and the web server spins up and reports it’s listening on port 4200.
-Ran docker inspect on my container and got the IP:

IE says the page cannot be reached.

Any other troubleshooting I can do to see where the disconnect is happening?

What is your image? node-ng is some kind of your own image? Can you post the dockerfile? Are you sure the webserver is running correctly?

I’m sorry, I literally just started with docker and node/angular yesterday, so I haven’t even learned about dockerfiles yet. But, it would be quite easy for you to replicate.

node-ng is a custom image. It’s the official node:6.9.1 image with angular-cli installed. npm install -g angular-cli…that’s it. Then in a directory, I run: “ng new first-app”. Now, this hangs at the npm installation for me, so I have been cutting it off and just manually run “npm install” after the initial directories and files are created. After this is done, I run “ng serve”. That is the web server that angular-cli spins up.

@michaelmello I think you’d just want to run docker run -p 4200:4200 <your-other-stuff>. With that, your in-container app should be exposed on localhost:4200.


I’m having almost the same exact issue. I’m trying to use docker to run an akka-http (scala) server, and cannot access it for the life of me. I’ve tried exposing the port it runs on with --expose and connecting via it’s IPAddress value from container inspect. I’ve tried port mapping. I’ve tried port mapping from various host ports just in case that was somehow the issue. Nothing. I’ve tested the code locally on my windows 10 machine and it works perfectly. I’m doing an sbt run using this project: On my host computer, it starts up with the message: “Server online at http://localhost:8080/” I can then access the site by typing that in my browser. Running on my custom ubuntu docker image yields the same message. Yet I cannot access it from my browser using http://:8080 (after exposing 8080) nor can I access it with localhost: after mapping to 8080 on docker run.

Hi everybody!
I spent a day to solve the issue and I found some trick:
I tried to deploy angular app ( in docker container in my Win10 by command
docker run -p 8000:8000 <other-stuff>
As described, locally project work fine.
Even inside container everything works fine(I checked by executing curl request inside container):
docker exec -it <container> bash -c 'curl http://localhost:8000'
But outside of container I still had the same issue as in posts above. page cannot be reached
The node.js app uses node http-server ( that allow you get name to host (“host1”, “myhost”, “localhost”) and that it start command from package.json:
"start": "http-server ./app -a localhost -p 8000 -c-1",
Intresting, because by default node http-server use that bind adress to real localhost ( flag -a look at npm documentation ) So when you start your container you can connect to and localhost inside docker.
But if you use -a localhost flag, you create alias for adress and localhost it is not real localhost( and you can’t get it outside of container.

Try to change your start script for using default adress (without -a flag)
"start": "http-server ./app -p 8000 -c-1",
It works for me, maybe it helps you.

docker container run -p 8083:9090 image_name/image_id : here 9090 is port in container and 8083 is os port . now we cal access it in browser as localhost:8083

I’m sorry but this command simply does not work! I have seen it so many times on different posts. maybe Docker have changed something recently. All I get is " This site can’t be reached"

Did you ever get this to work? I am trying to do something similar on ubuntu and I can’t access the app on local host using any of the suggestions in the comments