私はDocker環境で単純なLAMPスタックを作成しようとしています。サードパーティのコンテナphpdockerio/php71-fpm:latest
を実行することによって動作しましたが、XDebugをインストールしたカスタムPHPコンテナが必要でした。docker-composeを使用してPHPコンテナをnginxコンテナに接続するにはどうすればよいですか?
私の問題は、docker-compose up
を実行すると、起動後にPHPコンテナが終了してから、Webサーバーコンテナがそれを利用できるようになることです。どうすれば私のnginxコンテナの接続を待つようPHPコンテナに伝えることができますか?
コマンドライン出力
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
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' –
programmerq
@programmerqを実行してその出力を見ることができます。 _:)_ – Pyth0n