Docker:上游应用程序中找不到主机:9000

Kal*_*Kal 3 nginx docker

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

这让我相信这个问题与DNS有关.

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

我不确定这意味着什么.这是我的nginx conf:

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;
}
Run Code Online (Sandbox Code Playgroud)

还有我的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
Run Code Online (Sandbox Code Playgroud)

回购在这里.

有谁知道如何纠正这个问题?

谢谢

Der*_*ley 8

您的nginx容器可能在您的应用之前启动.你应该在depends_ondocker-compose.yml文件中添加一个部分,告诉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
Run Code Online (Sandbox Code Playgroud)