hrvojek's avatar

Basic setup with docker issues

Hi! I'm a noob with docker :) So please have understanding! I'm on MacOS.

I'm running MySQL with PHP8.2.

I have set it up using laravel sail & breeze, works fine... however issues with database env variables, as either it works in browser or it works in artisan (macos terminal, not using docker terminal)

#This works for artisan migrate, but localhost says connection refused
#DB_HOST=0.0.0.0

#This works for localhost, but artisan says getaddrinfo for host.docker.internal failed
#DB_HOST=host.docker.internal

#Artisan No such file or directory, localhost not working
#DB_HOST=localhost

#Container_name:db works for localhost, artisan says getaddrinfo for db failed:
DB_HOST=db

So I would want to make it work both in localhost browser but also use php artisan using macos terminal, is that even possible?

0 likes
7 replies
Sinnbeck's avatar

It should work. Just be sure to run sail artisan instead of php artisan

1 like
hrvojek's avatar

@Sinnbeck Yeah just saw that somewhere and tried, I get

sail artisan migrate
Usage: sail [OPTIONS] COMMAND [ARGS]...
Try 'sail --help' for help.
Error: No such command 'artisan'.

Brew uninstall sail worked for that, checking further how to rebuild :)

hrvojek's avatar

@Sinnbeck No, I rebuilt sail on laravel and again same error.

When I run

sail artisan migrate 

in MacOS terminal I get "command not found: sail"

When I run

php artisan migrate

I get

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for host.docker.internal failed

Meanwhile localhost works fine and phpyadmin work fine.

thinkverse's avatar
Level 15

Did you install Laravel Sail correctly? If you used brew install sail then you installed a CLI tool for Wordpress and not Laravel Sail.

If you installed your Laravel app using the Getting Started On macOS section, then it will have installed and configured Laravel Sail for you, and you can access sail via ./vendor/bin/sail, as shown in the documentation.

I know installing Laravel via the installers ships with Laravel Sail as a dev dependency, but I don't think it's installed by default. To install it, follow the directions found in Installing Sail Into Existing Applications, that would be.

php artisan sail:install

To publish Laravel Sail's docker-compose.yml file. And then you can use ./vendor/bin/sail to access Sail.

If you ever see any user just use sail to access Laravel Sail, then they've Configures A Shell Alias for it, which the documentation also covers.

alias sail='[ -f sail ] && sh sail || sh vendor/bin/sail'

With this alias in your ~/.zshrc or ~/.bashrc or ~/.bash_profile, depending on which shell ever you normally use. You can now use sail instead of ./vendor/bin/sail.

If you're using a command called sail already, then name your alias something else. 🙂

1 like
hrvojek's avatar

@thinkverse A note before anything further, php artisan migrate works and fills the database, but with that DB HOST, localhost says connection refused.. if I change to other values (as above) artisan stops working, localhost works...

Yeah I had the brew sail installed, however for the project I used artisan sail:install and it all works.. just depending on DB_HOST setting, macos terminal cannot run

php artisan migrate

or local host says connection refused but then php artisan works fine...

so as far as I understand logically... if mac os terminal throws something like

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for db failed

I guess that macos does not understand what address is "db" .. then I tried IP, tried ports, tried reinstalling everything fresh... tried exposing 3306 port etc...

Could it be that my macos somehow does not have full permissions (I have full disk access for docker ... )...

Any ideas are welcome or if you need more info...

hrvojek's avatar

Wow... I'm really dumb... I was sure I setup the sail alias, I probably "lost it" ... basically I re-set the alias and everything works... thanks @sinnbeck @thinkverse

thinkverse's avatar

@hrvojek yeah, you cannot use networks outside of Docker, since Docker's internal DNS is resolving those for you. That is why you need to run sail artisan or ./vendor/bin/sail without the alias, so that the call is proxied to your Sail container.

1 like

Please or to participate in this conversation.