For most of our Laravel projects we use Laradock and Docker to locally test and develop. Our most recent fresh start was slightly frustrated by an error within docker itself. We had git deployed our Laradock environment but when we came to start the container we received the following errors
Error response from daemon: Ports are not available: listen tcp 0.0.0.0:2222: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
Error response from daemon: Ports are not available: listen tcp 0.0.0.0:3001: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
This particular development environment uses Windows 10 which had recently been updated. After some research we ran the following command within PowerShell.
netsh interface ipv4 show excludedportrange protocol=tcp
This showed that both of those two ports required by docker (ports 2222, 3000 & 3001) were all added to an exclusion list and thus inaccessible to Docker.
Further digging uncovered Windows Network Address translation service as the trouble maker in our particular instance.
To resolve it we first stopped the service using the following command
net stop winnat
Following this we need to reserve that port for docker so that no other service can take that port. (Be careful with this command if you are unsure what that port is doing). The following will exclude port 2222, if you need others simply change the start port number.
netsh int ipv4 add excludedportrange protocol=tcp startport=2222 numberofports=1