Celeb Glow
news | February 26, 2026

cannot access to http://localhost:4000 after I map this port number to docker

This is my first time to use docker. I just followed the steps on docker's webiste: After I finished every steps, I cannot access from the browser.(These steps in the link will map 80 to 4000 in the docker) Here is the configuration for my docker:

$ docker ps
CONTAINER ID IMAGE COMMAND
STATUS PORTS NAMES
d204920463a9 firendlyhello "python app.py"
Up 6 minutes 0.0.0.0:4000->80/tcp pensive_bell

When I run this app:

liyuan.liu@USEUG-98T5N32 MINGW64 ~/test
$ docker run -p 4000:80 firendlyhello
* Running on (Press CTRL+C to quit)

Then I was trying to open in my browser, but it just said:This site can’t be reached. This is the app.py content:

liyuan.liu@USEUG-98T5N32 MINGW64 ~/test
$ cat app.py
from flask import Flask
from redis import Redis, RedisError
import os
import socket
# Connect to Redis
redis = Redis(host="redis", db=0)
app = Flask(__name__)
@app.route("/")
def hello(): try: visits = redis.incr('counter') except RedisError: visits = "<i>cannot connect to Redis, counter disabled</i>" html = "<h3>Hello {name}!</h3>" \ "<b>Hostname:</b> {hostname}<br/>" \ "<b>Visits:</b> {visits}" return html.format(name=os.getenv('NAME', "world"), hostname=socket.gethostname(), visits=visits)
if __name__ == "__main__": app.run(host='0.0.0.0', port=80)
4

1 Answer

Docker configures its own default IP address, which you can see whenever you launch Docker Quickstart Terminal.

Instead of , type address:4000]

You can also use this command to find the IP that Docker has configured:

docker-machine ip default

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy