I have a Docker container with PHP-FPM installed. To start it with -d option I tried this, but the container exits immediately:
docker run -d --name u12php53 -p 9001:9000 php53 /usr/local/etc/php-fpm.sh
The content of /usr/local/etc/php-fpm.sh
is:
service php5-fpm start && tail -F /var/log/php5-fpm.log
if I start the docker like this:
docker run -it --name u12php53 -p 9001:9000 -v php53
and start php-fpm.sh
manually, PHP-FPM
works fine and its log file is printed to stdout.
The final goal is to configure Docker to start my container with the system starts (or reboots).
答案 0 :(得分:2)
问题在于:service php5-fpm start
。执行此命令时,php-fpm将从shell中分离出来。但Docker仅在主进程存活时才能工作。
尝试像official image一样运行php-fpm:只需删除入口点并添加CMD ["php-fpm"]
。
另外,为什么要创建自己的php-fpm图像?您可以使用official图片吗?
答案 1 :(得分:0)
解决方案可能是:
docker run -d --name u12php53 -p 9001:9000 -v php53 bash -c '/usr/local/etc/php-fpm.sh'
可能它相当于在Dockerfile中执行此操作:
CMD ["sh", "/usr/local/etc/php-fpm.sh"]