Laravel Sail: Cannot create container for service laravel.test: invalid IP address in add-host: "host-gateway"

If you are starting a new Laravel project with Sail and hit with an error similar to this:

Cannot create container for service laravel.test:
invalid IP address in add-host: "host-gateway"

I can help you out. It's a simple fix 💪️

Solution for invalid IP address in add-host: "host-gateway" #

  1. Open the docker-compose.yml-file in your Laravel project folder
  2. Comment out the lines under extra-hosts:
         #    extra_hosts:
         #     - 'host.docker.internal:host-gateway'
    
  3. Run sail up -d --force-recreate to start Laravel Sail again with the new config.
  4. Win 🎉️

That's it! Simple as that.

🙏🙏🙏

Since you've made it this far, sharing this article on your favorite social media network would be highly appreciated 💖! For feedback, please ping me on Twitter.

Published