How to restart php-fpm inside a docker container?

后端 未结 4 1652
天涯浪人
天涯浪人 2021-01-30 17:13

I\'m using docker and my container is build over php:5.6-fpm image from php official repo. Is it somehow possible to restart/reload php-fpm from inside a container?

相关标签:
4条回答
  • 2021-01-30 17:38

    You don't have to go inside the container

    on your host ps -ef|grep fpm // find master pid kill -USR2 <master_pid>

    0 讨论(0)
  • 2021-01-30 17:42

    You can also just restart the container..

    sudo docker restart <container>
    
    0 讨论(0)
  • 2021-01-30 17:51

    php-fpm is a process manager which supports the USER2 signal, which is used to reload the config file.

    From inside the container:

    kill -USR2 1
    

    Outside:

    docker exec -it <mycontainer> kill -USR2 1
    

    Complete example:

    docker run -d --name test123 php:7.1-fpm-alpine
    docker exec -it test123 ps aux
    docker exec -it test123 kill -USR2 1
    docker exec -it test123 ps aux
    
    0 讨论(0)
  • 2021-01-30 17:53

    This works for me:

    If the command fpm restart fails run this inside the Docker container -> www#:

    root@...:/var/www# **ps -ef|grep fpm**  
    www-data   160     1  0 10:02 ?        00:00:00 php-fpm: pool www  
    www-data   161     1  0 10:02 ?        00:00:00 php-fpm: pool www  
    root      1111   170  0 10:04 pts/0    00:00:00 grep --color=auto fpm  
    
    root@...:/var/www# **kill -USR2 170**  
    
    root@...:/home/user/Docker# **docker-compose stop**  
    Stopping docker_nginx_1  ... done  
    Stopping docker_oracle_1 ... done  
    
    root@...:/home/user/Docker# **docker-compose up -d**  
    Starting docker_oracle_1 ... done  
    Starting docker_nginx_1  ... done  
    
    root@...:/home/user/Docker# **docker-compose exec oracle bash**
    
    root@...:/var/www# **/etc/init.d/php7.2-fpm restart**  
     * Restarting PHP 7.2 FastCGI Process Manager php-fpm7.2                                          **[ OK ]** 
    
    0 讨论(0)
提交回复
热议问题