When stuck with this Docker error:
Docker Error “bind: address already in use”
- This is a common issue that Docker users frequently encounter, especially when running multiple containers or services on the same machine.
- Typically, this error signifies that another process on the host system is already using the port your container is attempting to bind to.
In this guide, we’ll break down the root cause of the Docker Error “bind: address already in use” and walk you through several effective ways to resolve it. Whether you’re working on a development setup or deploying containers in production, these solutions will help you get your containers up and running smoothly.
- When starting a Docker container, you might see an error like this:
Error response from daemon: Cannot start container: listen tcp 0.0.0.0:9306: bind: address already in use
This means Docker is trying to bind a container port to a host port, but that host port is already occupied—usually by another process or container.
Solution Steps—Docker Error “bind: address already in use”
1. Kill the Process Using the Port
To run the container successfully, you must either stop the process using the port or change the port Docker uses.
Step-by-step:
- Check what is using the port (replace 8080 with your actual port):
sudo lsof -i tcp:8080
- You’ll get output showing the process ID (PID) using that port.
- Confirm it’s a non-essential process, then kill it:
sudo kill -9 <PID>
Replace the <PID> with actual process id obtained from previous command
2. Change to Another Port in Docker
If the port is essential to your system (e.g., used by another app you need), update your Docker setup to use a different port.
- Find a free TCP port, e.g., 8086
- Delete the existing Docker container:
docker rm <docker_name>
- Run your container again with a different host port:
docker run -d -p 8086:8080 -p 55555:55555 -p 80:80 --shm-size=2g --env username_admin_globalaccesslevel=admin --env username_admin_password=admin --name docker_name solace/solace-pubsub-standard
When Docker creates a container, it binds the ports at creation time. To change them, you must remove and recreate the container.
3. Restart Apache (if host was rebooted)
After a system reboot, services like Apache may occupy ports Docker wants to use.
You can restart Apache to clear any binding issues:
sudo /etc/init.d/apache2 restart
or
sudo apachectl -k restart
4. Stop Nginx if Running Globally
Sometimes, Nginx might be running and occupying a conflicting port. To stop Nginx:
sudo nginx -s stop
To check if the same container is running elsewhere or if Docker is holding onto the port:
docker-compose down
Stop Docker Compose container (if using docker-compose.yml)
docker rm -fv $(docker ps -aq)
Remove all containers forcefully
sudo lsof -i -P -n | grep <port number>
See who is using the port
Summary
In summary, the Docker error “bind: address already in use” is most commonly caused by a port conflict on your host system. To resolve it, you can identify and terminate the process occupying the port, change the port in your Docker configuration, restart services like Apache or Nginx that might be using the port, or remove existing Docker containers to start with a clean slate. With these steps, you’ll be able to eliminate the conflict and get your container running smoothly.
Are you still seeing the “bind: address already in use” Docker error? Don’t let technical difficulties hold you back. For a prompt and dependable answer, get in touch with our knowledgeable DevOps Support Services team. We are available around-the-clock to assist with full-stack container administration and Docker problems.