如何在docker容器内重启php-fpm?

时间:2016-06-14 07:58:01

标签: php docker

我使用的是docker,我的容器是基于php构建的:来自php official repo的5.6-fpm图像。 是否有可能从容器内重启/重新加载php-fpm?

5 个答案:

答案 0 :(得分:24)

php-fpm是一个进程管理器,它支持USER2信号,用于重新加载配置文件。

从容器内部:

kill -USR2 1

外:

docker exec -it <mycontainer> kill -USR2 1

完整示例:

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

答案 1 :(得分:2)

这对我有用:

如果命令fpm restart失败,请在Docker容器中运行此命令-> 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 ]** 

答案 2 :(得分:0)

您不必进入容器内

在您的主机上 ps -ef|grep fpm // find master pid kill -USR2 <master_pid>

答案 3 :(得分:0)

您也可以只重新启动容器。

var parameter = Expression.Parameter(typeof(T));

var nullConst = Expression.Constant(null);
Expression source = parameter, condition = null;
foreach (var memberName in expressionString.Split('.'))
{
    var notNull = Expression.NotEqual(source, nullConst);
    condition = condition != null ? Expression.AndAlso(condition, notNull) : notNull;
    source = Expression.PropertyOrField(source, memberName);
}
source = Expression.Convert(source, typeof(object));
var body = Expression.Condition(condition, source, nullConst);

return Expression.Lambda<Func<T, object>>(body, parameter)
                   .Compile();

答案 4 :(得分:-1)

docker container kill --signal USR2 php_container_name

详情:https://docs.docker.com/engine/reference/commandline/container_kill/