【问题标题】:Docker: Host not found in upstream app:9000Docker:在上游应用程序中找不到主机:9000
【发布时间】:2017-05-31 13:31:01
【问题描述】:

这个作曲家文件在一周前还可以工作(没有变化)。通过将dns: 8.8.8.8 添加到docker-compose.yml 文件中,我让它在家里再次工作。

这让我相信问题与 DNS 有关。

现在尝试在另一台机器上运行它(工作中),但出现以下错误: nginx: [emerg] host not found in upstream "app:9000" in /etc/nginx/sites-enabled/default.conf:2

我不确定这意味着什么。这是我的 nginx 配置文件:

server {
    listen 80;
    listen 443 ssl http2;

    # Server name being used (exact name, wildcards or regular expression)
    server_name localhost;
    client_max_body_size 200M;

    # Document root, make sure this points to your Phalcon web directory
    root /var/www/html/public;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?_url=$uri&$args;
    }

    location ~ \.php$ {
       fastcgi_pass app:9000;
       # regex to split $uri to $fastcgi_script_name and $fastcgi_path
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       fastcgi_index index.php;

       include fastcgi_params;

       # Bypass the fact that try_files resets $fastcgi_path_info
       # see: http://trac.nginx.org/nginx/ticket/321
       set $path_info $fastcgi_path_info;
       fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
       fastcgi_param APPLICATION_ENV development;

       #add_header Authorization $http_authorization;
    }

    # Logging
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
}

还有我的 docker-compose.yml 文件:

db:
  image: mysql:latest
  container_name: dev_db
  expose:
    - "3306"
  ports:
    - "3307:3306"
  environment:
    MYSQL_DATABASE: dbname
    MYSQL_USER: person
    MYSQL_PASSWORD: secret
    MYSQL_ROOT_PASSWORD: secret
app:
  image: linxlad/php7-fpm
  container_name: dev_app
  tty: true
  ports:
   - "6900:6900"
  volumes:
   - ./logs/php-fpm:/var/log/php-fpm
   - ..:/var/www/html
  links:
   - db
web:
  tty: true
  image: linxlad/nginx
  container_name: dev_web
  ports:
   - "8080:80"
  volumes:
   - ./conf/nginx:/etc/nginx/conf.d
   - ./logs/nginx:/var/log/nginx
   - ..:/var/www/html
  links:
   - app

回购是here

有人知道如何解决这个问题吗?

谢谢

【问题讨论】:

  • 你在app部分映射6900端口,不应该是9000吗?
  • @Emer 我尝试将其更改为 9000:9000(以前用作 6900:6900),停止并删除了容器,但仍然出现相同的错误:/

标签: nginx docker


【解决方案1】:

您的 nginx 容器可能在您的应用程序之前启动。你应该在 docker-compose.yml 文件中添加一个depends_on 部分,告诉 docker 容器应该以哪个顺序启动

https://docs.docker.com/compose/compose-file/#depends_on

web:
  tty: true
  image: linxlad/nginx
  container_name: dev_web
  ports:
    - "8080:80"
  volumes:
    - ./conf/nginx:/etc/nginx/conf.d
    - ./logs/nginx:/var/log/nginx
    - ..:/var/www/html
  links:
    - app
  depends_on:
    - app

【讨论】:

  • 那行得通,谢谢 :) 注意:如果我想要 version: "3",我会在文档中阅读 Version 3 no longer supports the condition form of depends_on.。在那种情况下我需要做什么?
  • 我从未使用过condition 表单,所以我不知道。不过,很高兴这有效!这是我以前遇到过的事情,所以我希望它对你来说很简单:)
  • 谢谢!我整天都在努力解决这个问题
猜你喜欢
  • 2020-07-08
  • 2018-03-03
  • 2019-09-01
  • 2021-02-26
  • 1970-01-01
  • 2016-02-11
  • 1970-01-01
  • 2018-02-06
  • 2021-04-21
相关资源
最近更新 更多