我最近开始迁移到 Docker 1.9 和 Docker-Compose 1.5 的网络功能来替换使用链接。
到目前为止,通过 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 调用?
原文由 Attila Szeremi 发布,翻译遵循 CC BY-SA 4.0 许可协议
有可能使用“volumes_from”作为解决方法,直到引入了 depends_on 功能(在下面讨论)。您所要做的就是更改您的 docker-compose 文件,如下所示:
上述方法中的一个重要警告是 php 的卷暴露给 nginx,这是不希望的。但目前这是一个可以使用的特定于 docker 的解决方法。
depends_on 功能 这可能是一个未来主义的答案。因为该功能尚未在 Docker 中实现(截至 1.9)
在 Docker 引入的新网络功能中,有一个提议要引入“depends_on”。但是对于相同的问题存在长期争论@ https://github.com/docker/compose/issues/374 因此,一旦实现,特性depends_on 可用于命令容器启动,但在时刻,您将不得不诉诸以下方法之一: