How to Fix “Port Already In Use” in Docker (2026 Guide)

The Short Answer

To fix the “Port Already In Use” error in Docker, stop the container or process currently using the port, or use the -p flag to specify a different port mapping. For example, if you’re trying to run a container on port 8080, but it’s already in use, you can use the command docker run -p 8081:8080 my-image to map port 8081 on the host machine to port 8080 in the container.

Why This Error Happens

  • Reason 1: The most common cause of this error is that another container or process is already using the port you’re trying to bind to. For instance, if you’re trying to run a web server container on port 80, but you already have a container running on that port, Docker will throw an error.
  • Reason 2: An edge case cause of this error is that the port is being held by a zombie process or a process that’s not properly releasing the port when it exits. This can happen if a container crashes or is killed without properly cleaning up its resources.
  • Impact: When this error occurs, the container will not start, and you’ll see an error message indicating that the port is already in use.

Step-by-Step Solutions

Method 1: The Quick Fix

  1. Go to Settings > Network > Ports
  2. Toggle Auto-map ports to Off
  3. Refresh the Docker dashboard to apply the changes.

Method 2: The Command Line/Advanced Fix

You can use the docker ps command to find the container ID of the container using the port, and then use the docker stop command to stop it. For example:

1
2
3
docker ps -a
docker stop <container_id>
docker run -p 8080:8080 my-image

Alternatively, you can use the lsof command to find the process ID of the process using the port, and then use the kill command to kill it. For example:

1
2
3
lsof -i :8080
kill <process_id>
docker run -p 8080:8080 my-image

Prevention: How to Stop This Coming Back

To prevent this error from happening in the future, make sure to:

  • Use a best practice configuration, such as using a port range or a specific IP address, to minimize port conflicts.
  • Monitor your containers and processes regularly to ensure that they’re not holding onto ports unnecessarily.
  • Use tools like docker-compose to manage your containers and ports, which can help prevent port conflicts.

If You Can’t Fix It…

[!WARNING] If Docker keeps crashing due to port conflicts, consider switching to Podman which handles address binding conflict fix natively without these errors.

FAQ

Q: Will I lose data fixing this? A: No, fixing the “Port Already In Use” error will not result in data loss. However, if you’re stopping a container to free up a port, make sure to commit any changes or save any data before stopping the container.

Q: Is this a bug in Docker? A: No, this is not a bug in Docker. The “Port Already In Use” error is a normal error that occurs when a port is already in use by another container or process. Docker versions 20.10 and later have improved port management features, such as the ability to specify a port range, which can help prevent this error.


📚 Continue Learning

Check out our guides on Docker and Port Already In Use.