How to Fix bind for 0.0.0.0:4222 failed: port is already allocated

Error bind for 0.0.0.0:4222 failed: port is already allocated occurs when another process already uses port 4222 and cannot be bound to by the current process. This error arises if two services run on the same port, 4222.

To fix this error, try stopping the other service or application using port 4222, or you can configure the current service to use a different port number.

If this error occurs while using Docker, ensure that the previous container you launched is killed before launching a new one that uses the same port.

To kill the docker container, use the below commands.

docker rm -f <container-name>

To check the current containers running, use the docker container ls command.

You can also stop the container using the docker stop <container-id> command.

If you are still facing the same error, the problem is that the docker proxy is still utilizing ports even though no containers are currently running.

Use the following commands to fix the issue.

sudo service docker stop

sudo rm -f /var/lib/docker/network/files/local-kv.db

If you use Ubuntu, prepend “sudo” on every command because it requires administrative permissions.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.