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

我试图在Docker环境中创build一个简单的LAMP堆栈。 它通过运行第三方容器phpdockerio/php71-fpm:latest ,但是我想要一个安装了XDebug的自定义PHP容器。

我的问题是,如果我执行docker-compose up ,启动后的PHP容器退出之前,我的webserver容器可以使用它。 我怎样才能成功告诉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"] 

泊坞窗,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 

nginxconfiguration

 ... 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

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