Docker 容器如何使用PHP-FPM在后台一直运行
在官方的centos基础上启动了一个容器,在里面安装了PHP-FPM.
现在我想让这个容器在后台运行,由另一个容器(如NGINX服务器容器)来连接它的PHP-FPM服务
以下是我的启动参数:
<code>#test/php是镜像名称 docker -d --name php-fpm test/php /usr/sbin/php-fpm </code>
<code>docker -d --name php-fpm test/php /usr/sbin/php-fpm -D #daemonize </code>
容器里好像是不能通过服务启动php-fpm
<code>[root@5233bbc57e72 /]# systemctl start php-fpm Failed to get D-Bus connection: No connection to service manager. </code>
于是安装个supervisor试试
<code>#/etc/supervisord.conf [supervisord] logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB) logfile_backups=10 ; (num of main logfile rotation backups;default 10) loglevel=info ; (log level;default info; others: debug,warn,trace) pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) nodaemon=true ; (start in foreground if true;default false) minfds=1024 ; (min. avail startup file descriptors;default 1024) minprocs=200 ; (min. avail process descriptors;default 200) ;umask=022 ; (process file creation umask;default 022) ;user=chrism ; (default is current user, required if root) ;identifier=supervisor ; (supervisord identifier, default is 'supervisor') ;directory=/tmp ; (default is not to cd during start) ;nocleanup=true [include] files = supervisord.d//*.ini [program:php-fpm] command=/bin/bash -c "/usr/sbin/php-fpm -D" </code>
启动
<code>docker run -d test/php /usr/bin/supervisord </code>
如果可以容器可以维持在后台运行,但是php-fpm没有启动!
php-fpm的配置是默认的
回复内容:
在官方的centos基础上启动了一个容器,在里面安装了PHP-FPM.
现在我想让这个容器在后台运行,由另一个容器(如NGINX服务器容器)来连接它的PHP-FPM服务
以下是我的启动参数:
<code>#test/php是镜像名称 docker -d --name php-fpm test/php /usr/sbin/php-fpm </code>
<code>docker -d --name php-fpm test/php /usr/sbin/php-fpm -D #daemonize </code>
容器里好像是不能通过服务启动php-fpm
<code>[root@5233bbc57e72 /]# systemctl start php-fpm Failed to get D-Bus connection: No connection to service manager. </code>
于是安装个supervisor试试
<code>#/etc/supervisord.conf [supervisord] logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB) logfile_backups=10 ; (num of main logfile rotation backups;default 10) loglevel=info ; (log level;default info; others: debug,warn,trace) pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) nodaemon=true ; (start in foreground if true;default false) minfds=1024 ; (min. avail startup file descriptors;default 1024) minprocs=200 ; (min. avail process descriptors;default 200) ;umask=022 ; (process file creation umask;default 022) ;user=chrism ; (default is current user, required if root) ;identifier=supervisor ; (supervisord identifier, default is 'supervisor') ;directory=/tmp ; (default is not to cd during start) ;nocleanup=true [include] files = supervisord.d//*.ini [program:php-fpm] command=/bin/bash -c "/usr/sbin/php-fpm -D" </code>
启动
<code>docker run -d test/php /usr/bin/supervisord </code>
如果可以容器可以维持在后台运行,但是php-fpm没有启动!
php-fpm的配置是默认的
- 直接使用官方的PHP Docker 镜像。
https://registry.hub.docker.com/_/php/ - 查看官方的 Docker 镜像的dockerfile 文件如何使用的。
https://github.com/docker-library/php/blob/32887c1de338d0ad582393b5f1d...

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

退出 Docker 容器的四種方法:容器終端中使用 Ctrl D 快捷鍵容器終端中輸入 exit 命令宿主機終端中使用 docker stop <container_name> 命令宿主機終端中使用 docker kill <container_name> 命令(強制退出)

PHP主要是過程式編程,但也支持面向對象編程(OOP);Python支持多種範式,包括OOP、函數式和過程式編程。 PHP適合web開發,Python適用於多種應用,如數據分析和機器學習。

PHP適合網頁開發和快速原型開發,Python適用於數據科學和機器學習。 1.PHP用於動態網頁開發,語法簡單,適合快速開發。 2.Python語法簡潔,適用於多領域,庫生態系統強大。

可以通過以下步驟查詢 Docker 容器名稱:列出所有容器(docker ps)。篩選容器列表(使用 grep 命令)。獲取容器名稱(位於 "NAMES" 列中)。

Docker 中將文件拷貝到外部主機的方法:使用 docker cp 命令:執行 docker cp [選項] <容器路徑> <主機路徑>。使用數據卷:在主機上創建目錄,在創建容器時使用 -v 參數掛載該目錄到容器內,實現文件雙向同步。

PHP的核心優勢包括易於學習、強大的web開發支持、豐富的庫和框架、高性能和可擴展性、跨平台兼容性以及成本效益高。 1)易於學習和使用,適合初學者;2)與web服務器集成好,支持多種數據庫;3)擁有如Laravel等強大框架;4)通過優化可實現高性能;5)支持多種操作系統;6)開源,降低開發成本。

重啟 Docker 容器的方法:獲取容器 ID(docker ps);停止容器(docker stop <container_id>);啟動容器(docker start <container_id>);驗證重啟成功(docker ps)。其他方法:Docker Compose(docker-compose restart)或 Docker API(參考 Docker 文檔)。

在 Docker 中啟動 MySQL 的過程包含以下步驟:拉取 MySQL 鏡像創建並啟動容器,設置根用戶密碼並映射端口驗證連接創建數據庫和用戶授予對數據庫的所有權限
