I run the images in docker terminal:
docker run -p 4000:80 friendlyhello
Localhost does not connect and display images.
This site can’t be reached
localhost refused to connect.
- Did you mean http://localhost4000.org/?
- Search Google for localhost 4000
ERR_CONNECTION_REFUSED
You just need to reference it by its Docker network IP, instead of localhost or 127.0. 0.1 . Your host's Docker IP will be shown on the inet line. Connect to this IP address from within your containers to successfully access the services running on your host.
Ok, your localhost server has a default docker interface docker0 with IP address 172.17. 0.1 .
Docker also finds ports you expose with --expose 8080 (assuming you want to expose port 8080). Docker maps all of these ports to a host port within a given epehmeral port range . You can find the configuration for these ports (usually 32768 to 61000) in /proc/sys/net/ipv4/ip_local_port_range .
i think maybe you visit http://localhost:4000 in browser on Windows,then you should use the docker default machine ip(generally 192.168.99.100). just try http://192.168.99.100:4000.
I had this problem too, solved following this part of the documentation:
Note: If you are using Docker Toolbox on Windows 7, use the Docker Machine IP instead of localhost. For example, http://192.168.99.100:4000/. To find the IP address, use the command docker-machine ip.
If you running a nodejs app in the docker container, try '0.0.0.0' instead of 'localhost'.
example: suppose your app works on port 3000
server.listen(3000, 'localhost' () => {
console.log('listening for requests on port 3000');
});
server.listen(3000, '0.0.0.0' () => {
console.log('listening for requests on port 3000');
});
then you can do port-mapping in docker to your web app.
docker run -p 4000:3000 --name 'your_container_name' 'your_image_name'
start the container and see the port using the below command on your cmd or terminal.
docker port <your_container_name>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With