Docker: Bind for 0.0.0.0:8080 failed: port is already allocated
Fix "port is already allocated" in Docker and Docker Compose: find the container or program that holds the port and free it.
This error appears when Docker tries to publish a container port on your computer and that port is already taken, by another container or by a normal program. Find who holds it, stop it, or publish on a different port.
What to do, step by step
- Read the port in the error, such as 8080.
- List running containers and look at the PORTS column: docker ps.
- If a container holds the port, stop it with docker stop name, or run docker compose down in the project that started it.
- If no container holds it, a normal program does. Find it with lsof -i :8080 (macOS, Linux) or netstat -ano | findstr :8080 (Windows).
- Or change the left number in your ports line, for example "8081:80". The right number stays the same.
Commands you can copy
docker psdocker stop container-namedocker compose downlsof -i :8080netstat -ano | findstr :8080Other causes to check
- Port shows free but the error remains
- An old container may be stopped but not removed. Run docker ps -a, then docker rm name. Restarting Docker Desktop also clears stuck port forwards.
- MySQL on 3306 fails
- A MySQL server is probably installed on your computer already. Publish the container on "3307:3306" and connect to port 3307.
- Windows: port is excluded by Hyper-V
- Windows reserves some ranges. Check with netsh interface ipv4 show excludedportrange protocol=tcp and choose a port outside them.
- Two Compose projects use the same port
- Give each project its own left-hand port number.
Questions about Docker port already allocated
- What does the port mapping 8080:80 mean?
- The left number is the port on your computer. The right number is the port inside the container. Change the left one to avoid a clash.
- How do I stop all containers?
- Run docker stop with the names from docker ps, or docker compose down inside a project folder. Check what each container does before stopping it.
- Why is the port taken after I stopped my app?
- A different container or a background program may use it. Check docker ps -a and the port commands on this page.
Free tools that help
- Common ports listSearch a list of common TCP and UDP port numbers: SSH 22, HTTP 80, HTTPS 443, MySQL 3306, PostgreSQL 5432 and more, with dev server ports.
Config generators for this
- Dockerfile for Node.jsA small, working Dockerfile for a Node.js app, with build step, non-root user and health check options.
- Dockerfile for PythonA working Dockerfile for a Python web app, with Gunicorn, Uvicorn or a plain script.
- docker-compose for MySQLRun a local MySQL database in Docker with your own user, password and port, and keep the data between restarts.
- docker-compose for PostgreSQLRun a local PostgreSQL database that keeps its data.
- docker-compose for MongoDBRun a local MongoDB database with a password that keeps its data.
- docker-compose for RedisRun Redis in Docker with a password, saved data and a memory limit.
- docker-compose for WordPressRun WordPress and its database locally in Docker with one command and keep your site between restarts.
- Docker Compose for MailpitRun a fake mail server on your computer, so test emails from your app show up in a web page instead of being sent.
- Docker Compose for MySQL and phpMyAdminRun MySQL and the phpMyAdmin web page on your computer with one docker compose command.
- Docker Compose for PostgreSQL and pgAdminRun PostgreSQL and the pgAdmin web page on your computer with one docker compose command.