我最近开始迁移到Docker 1.9和Docker-Compose 1.5的网络功能,以使用链接进行替换。
到目前为止,nginx通过docker-compose连接到我的php5-fpm fastcgi服务器是没有问题的,该服务器位于一组中的另一台服务器中。最近,尽管当我运行docker-compose --x-networking up
php-fpm时,mongo和nginx容器会启动,但是nginx会立即退出[emerg] 1#1: host not found in upstream "waapi_php_1" in /etc/nginx/conf.d/default.conf:16
但是,如果我在运行php和mongo容器(退出nginx)时再次运行docker-compose命令,则nginx将启动并自此正常运行。
这是我的docker-compose.yml
文件:
nginx:
image: nginx
ports:
- "42080:80"
volumes:
- ./config/docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
php:
build: config/docker/php
ports:
- "42022:22"
volumes:
- .:/var/www/html
env_file: config/docker/php/.env.development
mongo:
image: mongo
ports:
- "42017:27017"
volumes:
- /var/mongodata/wa-api:/data/db
command: --smallfiles
这是我default.conf
的nginx:
server {
listen 80;
root /var/www/test;
error_log /dev/stdout debug;
access_log /dev/stdout;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/.+\.php(/|$) {
# Referencing the php service host (Docker)
fastcgi_pass waapi_php_1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# We must reference the document_root of the external server ourselves here.
fastcgi_param SCRIPT_FILENAME /var/www/html/public$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
我如何才能使nginx仅与单个docker-compose调用一起使用?