Docker入门教程执行docker run命令遭遇80端口占用错误的解决方案咨询
Troubleshooting "address already in use" for Docker Port 80
Hey there, that error pops up because port 80 on your machine is already being used by another process—not a Docker container (since you already cleared all those with docker rm -fv $(docker ps -aq)). Let's walk through how to fix this:
Step 1: Find out which process is hogging port 80
Use these commands based on your operating system to track down the culprit:
- Linux/macOS:
Look for thelsof -i :80 # Or an alternative command netstat -tulpn | grep :80PIDcolumn—this is the unique ID of the process using port 80. - Windows:
The last number in each line is thenetstat -ano | findstr ":80"PIDof the process occupying the port.
Step 2: Stop the conflicting process
Once you have the PID, kill the process to free up port 80:
- Linux/macOS:
Replacekill -9 <PID_NUMBER><PID_NUMBER>with the actual number from Step 1. If it's a system service like Apache or Nginx, you can also stop it directly (e.g.,sudo systemctl stop apache2on Ubuntu-based systems). - Windows:
Thetaskkill /F /PID <PID_NUMBER>/Fflag forces the process to shut down immediately.
Step 3: Alternative option - Use a different port for Docker
If you don't want to stop the existing process, just map Docker's internal port 80 to a different host port. For example:
docker run -d -p 8080:80 docker/getting-started
Now you can access the getting-started app by visiting localhost:8080 in your browser.
内容的提问来源于stack exchange,提问作者Borybar
相关产品推荐
相关产品推荐

