我正在尝试在 Docker 环境中创建一个简单的 LAMP 堆栈。它通过运行第三方容器来工作phpdockerio/php71-fpm:latest
,但目前我想要一个安装了 XDebug 的自定义 PHP 容器。
我的问题是,如果我执行docker-compose up
,PHP 容器会在启动后退出,然后我的网络服务器容器才能使用它。我怎样才能成功地告诉 PHP 容器等待我的 nginx 容器的连接?
命令行输出
PS C:\playground> docker-compose.exe up
Starting playground_php_1
Starting playground_web_1
Attaching to playground_php_1, playground_web_1
playground_php_1 exited with code 0
playground_web_1 exited with code 1
文件
FROM php:latest
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
ENTRYPOINT ["docker-php-entrypoint"]
CMD ["php", "-a"]
docker-compose.yml
version: '2'
services:
php:
build:
context: ./etc/php/
dockerfile: Dockerfile
volumes:
- './src:/usr/share/nginx/html'
web:
image: nginx:latest
ports:
- 8080:80
volumes:
- './etc/nginx:/etc/nginx/conf.d'
- './src:/usr/share/nginx/html'
depends_on:
- php
nginx配置
...
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
...
我再次使用我的自定义容器运行它。我将基本图像从 更改php
为php-fpm
。
我做的下一件事是我必须清除正在运行的容器并删除我机器上已经创建的图像。否则docker-compose
会再次使用错误/旧容器。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句