Docker executing a command when running an image - laravel

I'm using Laravel with docker. Inside my dockerfile I have this command:
RUN php artisan config:cache
This is useful for production since it cache the configuration. When I'm developing I need to be able to change the configuration quite often, so every time I run the image I need to execute
RUN php artisan config:clear
is there a way to run the docker image with a given command? i.e.:
docker run my_image "php artisan config:clear"
(If you're wondering, I'm doing docker run instead of docker start quite often since I'm building the image quite often.)
I'd like to avoid using CMD inside dockerfile since it's not really needed.
Thanks

If you want to run the command inside a currently running container you can use the exec command:
$ docker exec yourapp_web_1 php artisan config:clear

Related

Laravel Sail is not working properly in Ubuntu 20.04 LTS

Hi i tried to install fresh Laravel project using
Laravel Sail
docker environment. First it was showing me "Docker is not running" error. Then i found out, i needed to start docker as rootless. I solved it, reading this url: [https://docs.docker.com/engine/install/linux-postinstall/].
After that, I successfully installed Laravel using Laravel Sail. Then I ran
./vendor/bin/sail up -d
I was able to view Laravel project in my browser. But when i ran any other artisan commands such as ./vendor/bin/sail artisan route:list or sail commands as sail shell, all the docker containers were forced closed automatically. It shows me this error.
Sail is not running.
You may Sail using the following commands: './sail up' or './sail up
-d'
Any suggestions? I am getting this issue on Ubuntu 20.04 LTS version.
If you are on Windows and using WSL, make sure the WSL Integration is properly set:
Settings->Ressources->WSL Integration + Toggle Linux version
I was using Laradock before installing Laravel Sail. Maybe there were some conflicts. So I backed up all my databases, then I removed all containers using this code. sudo docker rmi -f $(docker images -a -q). Then installed fresh Laravel project and it worked.
Please read my below comment as it is was a better solution for me.
very easy, maybe you don't have permission to run docker.
in Linux first use sudo -s and after user ./vendor/bin/sail up -d
Sail first checks to see if any current docker-compose processes have a status of Exit. If any of them have, then it will forcefully bring down all other services. Which is what you were are seeing whenever you type any sail sub-command. You can see the code here: https://github.com/laravel/sail/blob/87c63c2956749f66e43467d4a730b917ef7428b7/bin/sail#L44-L49
Run sail up to start the processes and then use docker-compose ps to check all services are running and none have an Exit status.
I had the same issue and when reviewing the code and checking my services I noticed the database had exited soon after I brought them up.

How can I run php artisan and npm run electron at once?

I tried to run php artisan serve and electron . by using npm but only the php artisan serve is activating. I can access the 127.0.0.1:8000 using the browser but the electron desktop app is not running.
"scripts": {
"electron": "electron .",
"start": "php artisan serve & npm run electron",
}
That's because the execution of the php artisan serve command does not end until you stop it, so the npm run electron command is never going to start.
Trying to run the serve command in background (like using nohup) will result in troubles when stoping the execution of the npm script: The artisan serve process won't stop, so rerunning npm run start will start a new serve process on the next available port: 8001. You would need to find and kill each process manually.
The only option that comes into my mind is to set up an Apache/Nginx VirtualHost so you don't need to run the php artisan serve command.

Laravel: Ran artisan commands and now can't connect

I am working on the frontend for a friend's Laravel app and some of the Blade views got cached. After I ran the following code, I can't even connect to the localhost:
php artisan view:clear
php artisan cache:clear
php artisan config:cache
The site is running on Docker containers, so I even tried to restart them but still nothing but it comes up with a PHP error screen that says:
InvalidArgumentException in FileViewFinder.php line 137:
View [errors.no-store] not found.
So is it because I cleared the views?
It does not work when your machine is running on vagrant (or another virtual environment like docker) and you run php artisan config:cache out of vagrant. Do you need to run this command in vagrant? The problem is about path routes (path are not the same in vagrant and out of vagrant).
The same thing is with Docker. If there is a project in directory outside of container in shared location php artisan config:cache has to be run from within container.
Please refer to this answer.

How to disable artisan serve

I tried to run serve -s build in my React app after running npm run build.
I get the following error.
Could not open input file: artisan
I think this artisan is from Laravel. How can I run npm serve command rather than Laravel's one.

Laravel php artisan serve doesn't work

I have Laravel 5.3.16 installed. I have built my projects and until now it would work properly. but for the past few days I can't connect local host. I use the following command on mac terminal,
php artisan serve
and in terminal it's fine, but on my browser I get an error of server being busy!
can anyone tell me what is the problem?
The issue might be that the time you ran 'php artisan' serve wasn't stopped. You can check this by doing following steps:
Assuming you are on a OSX computer:
Open terminal
Run: ps -ef | grep php
Lookup if there is currently a Laravel process in use.
Get that id that is running the instance and kill it.
kill 012345
Try to run the command: php artisan serve again.

Resources