Bind for failed: port is already allocated

This is an issue that we got into when we tried to run a docker image on the port 8080. Following is the command that we tried:

$ docker run -it -p 8080:80 $(docker build -q .)

In our case, port 8080 was already allocated by other docker image container. We had to find the name of the docker container by running the following command:

$ docker container ls

This showed us the container that was holding 8080 port. In our case, the docker container was fairly old and was not in use. We removed it using the following command:

$ docker rm -f <CONTAINER_ID>

After removing the docker container, we were able to run the docker build without this error.