localhost:8888: the Jupyter Notebook port and how to fix it

localhost:8888 is the default port of Jupyter Notebook and JupyterLab. Running jupyter lab or jupyter notebook starts a server on http://localhost:8888 and opens your browser with a one-time token in the URL. If the page refuses to connect, the server isn't running; if it asks for a password or token, the server is running and wants you to log in.

What runs on port 8888

ToolCommandNotes
JupyterLabjupyter labDefault 8888
Jupyter Notebookjupyter notebookDefault 8888
Jupyter Docker Stacksdocker run -p 8888:8888 quay.io/jupyter/scipy-notebookToken printed in container logs
VS Code Jupyter (remote kernel)Connects to an existing serverUses the server's URL and token

A second server moves to 8889, 8890 and so on.

Fix "localhost:8888 refused to connect"

  1. Is the server running? The terminal shows Jupyter Server ... is running at: http://localhost:8888/lab?token=.... If you closed that terminal, the server stopped with it.
  2. List running servers:
    jupyter server list
    

    This shows each server's actual port and token. On older installs use jupyter notebook list.
  3. Docker. Use the http://127.0.0.1:8888/lab?token=... line from docker logs <container>. The hostname-based URL in the logs points to the container's own name, which your browser can't resolve.
  4. WSL2. Recent WSL forwards localhost to Windows. If it doesn't, start with --ip 0.0.0.0 and use the WSL IP.

"Password or token" page

That page means you reached Jupyter without the token. Copy the full URL including ?token=... from the terminal or jupyter server list, or set a password once with jupyter server password. Don't "fix" this by disabling authentication. A Jupyter server runs arbitrary code as your user, so anyone who can reach it without a token owns the machine.

Find and free a busy port 8888

jupyter server stop 8888        # clean shutdown
# or find the process
lsof -i :8888
kill -9 $(lsof -ti :8888)
# Windows
netstat -ano | findstr :8888
taskkill /PID <pid> /F

Pick a port explicitly with jupyter lab --port 8899, or set c.ServerApp.port = 8899 in jupyter_server_config.py.

Open Jupyter from another machine

The common case is Jupyter running on a GPU box or cloud VM. Two options:

SSH tunnel (best when you have SSH):

# on the server
jupyter lab --no-browser --port 8888
# on your laptop
ssh -L 8888:localhost:8888 user@gpu-box

Then open http://localhost:8888 locally with the token. Nothing new is exposed.

LAN access: jupyter lab --ip 0.0.0.0 --no-browser and open http://SERVER-IP:8888/?token=.... Only on a network you trust, and only with the token on.

Share Jupyter over a public URL

When there's no SSH path (the box is behind NAT, or a collaborator doesn't have an account on it), a tunnel gives the server an HTTPS address without opening inbound ports:

relay connect --name team-notebook http://localhost:8888

Keep token or password authentication enabled. The tunnel only makes the server reachable; Jupyter's own login is what stops strangers running code on your machine. If notebooks load but kernels keep disconnecting, the WebSocket connection to /api/kernels/... is failing; check that nothing between the browser and Jupyter strips WebSocket upgrades. Dotscience runs thousands of tunnels like this for hosted data science environments.

Frequently asked questions

What is localhost:8888?

localhost:8888 is the default port of Jupyter Notebook and JupyterLab. Running jupyter lab or jupyter notebook starts a server on http://localhost:8888 and opens it in your browser with a login token in the URL.

How do I find my Jupyter token?

Run jupyter server list (or jupyter notebook list on older installs). It prints each running server with its URL and token. The token is also printed in the terminal when the server starts.

Why is Jupyter on 8889 instead of 8888?

Another Jupyter server already holds port 8888, so the new one moved to the next free port. Stop the old server with jupyter server stop 8888 or pass --port to choose a port yourself.

How do I access Jupyter on a remote server?

The safest way is an SSH tunnel: run ssh -L 8888:localhost:8888 user@server, then open http://localhost:8888 on your own machine. Start Jupyter on the server with --no-browser and keep token or password authentication enabled.