When a container is occupying the same port to be used by a new process, a Docker error port is already allocated will be triggered in the server environment.
Here at IbmiMedia We have received support request about this error as part of our Server Support Services.
In this context, we shall look into why this error occur and how best to fix it.
Why does the Docker error , port is already allocated occur?
As we are about to find a solution to this Docker error, let us see why it happens.
Whenever, a port is occupied by a service, program or process, for another program to use same port, the process must undergo a kill process in the container.
In the scenario where we forget to kill the running process, the Docker error concerning the allocated port will be triggered.
In this situation , the running process will not allow any other container to run on the same port.
How to fix docker error port is already allocated
Below we will outline the process to take in solving this Docker issue.
To begin, the current running container and its ID needs to be detected. you can use the following command;
docker container ls
As soon as you discover the running container's ID lets say "container-ID" is the id of the current running container, you can use the following command to stop it;
docker stop container-ID
Finally, it will stop and you can then run the other process which was not allowed to run initially.