Docker Networking-nginx:在上游找不到[emerg]主机 [英] Docker Networking - nginx: [emerg] host not found in upstream

查看:152
本文介绍了Docker Networking-nginx:在上游找不到[emerg]主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始迁移到Docker 1.9和Docker-Compose 1.5的网络功能,以使用链接进行替换.

I have recently started migrating to Docker 1.9 and Docker-Compose 1.5's networking features to replace using links.

到目前为止,通过链接,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

So far with links there were no problems with nginx connecting to my php5-fpm fastcgi server located in a different server in one group via docker-compose. Newly though when I run docker-compose --x-networking up my php-fpm, mongo and nginx containers boot up, however nginx quits straight away with [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将启动并自此正常运行.

However, if I run the docker-compose command again while the php and mongo containers are running (nginx exited), nginx starts and works fine from then on.

这是我的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

这是我对nginx的default.conf:

This is my default.conf for 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调用一起使用?

How can I get nginx to work with only a single docker-compose call?

推荐答案

在引入depends_on功能(如下所述)之前,可以使用"volumes_from"作为解决方法.您要做的就是如下更改docker-compose文件:

There is a possibility to use "volumes_from" as a workaround until depends_on feature (discussed below) is introduced. All you have to do is change your docker-compose file as below:

nginx:
  image: nginx
  ports:
    - "42080:80"
  volumes:
    - ./config/docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
  volumes_from:
    - php

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

上述方法的一个重要警告是,php的体积暴露于nginx,这是不希望的.但是目前,这是可以使用的一种特定于docker的解决方法.

One big caveat in the above approach is that the volumes of php are exposed to nginx, which is not desired. But at the moment this is one docker specific workaround that could be used.

depends_on功能 这可能是一个未来派的答案.因为该功能尚未在Docker中实现(从1.9版本开始)

depends_on feature This probably would be a futuristic answer. Because the functionality is not yet implemented in Docker (as of 1.9)

有人建议在Docker引入的新网络功能中引入"depends_on".但是关于相同的@ https://github.com/docker/compose/issues/374 的争论由来已久a>因此,一旦实现,就可以使用功能depends_on来命令启动容器,但是此刻,您必须诉诸以下一种方法:

There is a proposal to introduce "depends_on" in the new networking feature introduced by Docker. But there is a long running debate about the same @ https://github.com/docker/compose/issues/374 Hence, once it is implemented, the feature depends_on could be used to order the container start-up, but at the moment, you would have to resort to one of the following:

  1. 使nginx重试直到php服务器启动-我更喜欢这个
  2. 如上所述,使用volums_from解决方法-由于卷会泄漏到不必要的容器中,因此我将避免使用它.

这篇关于Docker Networking-nginx:在上游找不到[emerg]主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆