Reputation: 1390
It is possible run "php artisan commands" from Host if the server is running into container, and how?
Upvotes: 6
Views: 26471
Reputation: 491
cd on my project
cd /Users/neisantos/src/laravel-project
considering I have a docker running using the name [APP]
alias artisan='[ -d /Users/neisantos/src/laravel-project ] && docker exec -it APP php artisan'
so I can only do the command below to execute artisan from my docker container.
artisan route:list
this alias will run only when running from the folder of my project.
Upvotes: 0
Reputation: 1018
when using package.json you could place it inside the "scripts" like
{
...
"scripts":{
"artisan": "docker exec -it CONTAINER-NAME php artisan --command process.env.command"
}
...
}
then you could execute artisan-commands like that:
migrate:
npm run artisan migrate
version
npm run artisan --version
Upvotes: 0
Reputation: 5939
if using docker-compose
docker-compose exec <container_name|id> bash
Upvotes: 0
Reputation: 1390
This is the solution! Ok, for a while, I thought I was crazy, but I did not. The trick is set a PHP into host (for the CLI), matching with the docker PHP version, so:
Upvotes: -3
Reputation: 91
You'd need to change the path references to suit your own project, but this allows you to execute the artisan command from your host machine on the container without having to login.
docker exec -it <php-fpm-container> /var/www/html/artisan
Upvotes: 8
Reputation: 3674
Client (php artisan
) on the host talking to server in a container is a solved problem:
This can be done in two ways. They make the server's port in the container accessible on the host:
Publish the server's port to the host by passing -p
to docker run
. More info is here.
docker run -p hostPort:containerPort ...
Use Docker's "host networking" by passing --network host
to docker run
. More info is here.
docker run --network host ...
Upvotes: 0
Reputation: 11636
To run commands from your host,
You can use Docker's exec
command like this:
docker exec -it my-container-name /bin/bash
After that, you can run any command you want
php artisan --version
Upvotes: 16