Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel CLI 'sail artisan' returns 'no such service' after updating 'service name' in docker-compose.yml

After creating a new Laravel project via Laravel Sail, a new project is created within a Docker container. When I updated the associated 'docker-composer.yml' file to rename the 'laravel.test' service, I closed it and rebuilt sail with the expectation that this would incorporate my changes to the service name using sail build --no-cache.

Ever since then, the command sail artisan returns an error 'ERROR: No such service: Laravel.test'

Exhaustive searches yielded no help.

like image 999
George Brotherston Avatar asked Jan 31 '21 18:01

George Brotherston


3 Answers

I have created a customized solution that is based off of Laravel's installation. It includes installation of XDebug and the latest node.js and NPM. It is a fully functional solution that also has all source code readily available sail.StonePlayground.com

I welcome comments.

--- Previous Answer ---
In the ./vendor/bin/sail file there are a few locations where I replaced 'laravel.test' with the value I have set in 'docker-composer.yml' (myApp.local). This also matches my '.env' APP_URL (less the http://). All is now working well!

I'm hoping this post is helpful to others who may run into a similar situation.

UPDATE: I found a much simpler way to accomplish this with no need to edit the vendor files. Just add APP_SERVICE="myApp.local" (or whatever your local URL is) to your .env file.

like image 83
George Brotherston Avatar answered Oct 22 '22 04:10

George Brotherston


I found a really great article about this topic and Larvel Sail in general.

What I realized after reading it is that the error says exactly what is happening, as usual. Your APP_SERVICE name has to match with the service name of your actuall laravel app container in docker-compose.yaml file, which is by default laravel.test. When you rename it, do what George suggested with APP_SERVICE .env variable. What is really important here though, is your service name, not APP_URL.

like image 34
smidkristian Avatar answered Oct 22 '22 03:10

smidkristian


When I read sail customization I misread this paragraph:

After customizing your Sail installation, you may wish to change the image name for the laravel.test service in your application's docker-compose.yml file. [...] Assigning a unique name to the laravel.test service image is particularly important if you are using Sail to develop multiple Laravel applications on a single machine:

I thought this means I should rename the service name and had the same error message that you had, and in this case setting APP_SERVICE is the right solution. However, it only states to rename the image name. Changing the image name in docker-compose.yml does work without adding additional environment variables.

like image 1
Adam Avatar answered Oct 22 '22 02:10

Adam