简体   繁体   中英

How run artisan commands from Host with docker containers

如果服务器运行到容器中,则可以从 Host 运行“php artisan commands”,以及如何运行?

您需要更改路径引用以适合您自己的项目,但这允许您从容器上的主机执行 artisan 命令,而无需登录。

docker exec -it <php-fpm-container> /var/www/html/artisan

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

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:

  1. Publish the server's port to the host by passing -p to docker run . More info is here .

     docker run -p hostPort:containerPort ...
  2. Use Docker's " host networking " by passing --network host to docker run . More info is here .

     docker run --network host ...

if using docker-compose

  1. first get into the container
docker-compose exec <container_name|id> bash
  1. now goto var/www/html directory and run your choice of command

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: 这张图片显示了这个技巧是如何工作的

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM