【发布时间】:2017-06-20 21:56:04
【问题描述】:
我正在尝试在 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
Dockerfile
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;
}
...
【问题讨论】:
-
任何时候你的容器化进程退出,容器都被认为是停止的。如果您的任何一个进程在退出之前在 stdout/stderr 上输出任何内容,您可以通过执行
docker logs <container_name_or_id>查看该输出 -
@programmerq 谢谢你的提示。 :)
标签: php nginx docker docker-compose