如何使用docker compose将PHP容器与nginx容器连接起来?

如何使用docker compose将PHP容器与nginx容器连接起来?,php,nginx,docker,docker-compose,Php,Nginx,Docker,Docker Compose,我试图在Docker环境中创建一个简单的灯堆栈。它通过运行一个第三方容器phpdockerio/php71 fpm:latest工作,但目前我想要一个安装了XDebug的定制PHP容器 我的问题是,如果执行docker compose up,PHP容器在启动后退出,然后我的Web服务器容器才能使用它。我如何才能成功地告诉PHP容器等待我的nginx容器的连接 命令行输出 PS C:\playground> docker-compose.exe up Starting playground

我试图在Docker环境中创建一个简单的灯堆栈。它通过运行一个第三方容器
phpdockerio/php71 fpm:latest
工作,但目前我想要一个安装了XDebug的定制PHP容器

我的问题是,如果执行
docker compose up
,PHP容器在启动后退出,然后我的Web服务器容器才能使用它。我如何才能成功地告诉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;
    }
...

我让它运行,再次与我的自定义容器。我将基本图像从
php
更改为
phpfpm


接下来我要做的是,我必须清除正在运行的容器,并删除我机器上已经创建的图像。否则,
docker compose
将再次使用错误/旧的容器。

任何时候容器化进程退出时,容器都会被视为停止。如果您的任一进程在退出之前在stdout/stderr上输出了任何内容,您可以通过执行
docker logs
@programmerq查看该输出,谢谢您的提示。:)