failed: port is already allocated failed: port is already allocated docker docker

failed: port is already allocated


you can't launch twice

docker run -d -p 49160:22

as this means you want to allocate the port 49160 on the host twice, of course, the second time, you get you error message, try for the second run

docker run -d -p 49161:22


You will need to use a different port instead of 49161. Try a port less than 49152.

You have a pre-existing connection between the the port 49161 on your computer and port 5223 on a remote Apple server. That port, therefore, cannot be used for anything else until that connection ceases to exist. Port 5223 is used for Apple's push notifications. As best as I can tell, your computer so happened to use the random port 49161 to connect to Apple's server this time. Previously when that Docker container worked, I would bet port 49161 on your computer was not then used.

Whenever you connect to a remote server, your own computer allocates a random port number for that connection. This time around, your computer allocated 49161 when it connected to Apple's push notifications service. Next time, it could be a completely different number. See https://en.wikipedia.org/wiki/Ephemeral_port