Jan Sršeň
Jan Sršeň

Reputation: 1095

Docker - nginx: host not found in upstream

I download official docker packages, and then I set docker-compose. Everything compiles OK, but if I get docker-compose up, I got this error message:

project-websrv | 2017/09/22 10:18:35 [emerg] 1#1: host not found in upstream "php-fpm" in /etc/nginx/conf.d/default.conf:25
project-websrv | nginx: [emerg] host not found in upstream "php-fpm" in /etc/nginx/conf.d/default.conf:25
project-php exited with code 0

nginx.conf line 25:

fastcgi_pass php-fpm:9000;

my docker-compose.yml

version: "3.1"
services:

    mysql:
      image: mariadb
      container_name: project-mariadb
      environment:
        MYSQL_ROOT_PASSWORD: root

    phpmyadmin:
      image: phpmyadmin/phpmyadmin
      container_name: project-pma
      restart: always
      links:
        - mysql
      ports:
        - 8183:80
      environment:
        PMA_HOST: mysql
        PMA_USER: root
        PMA_PASSWORD: root

    php-fpm:
      build: php
      container_name: project-php
      working_dir: /var/www/project
      volumes:
        - ../../Sources/project/trunk/src/:/var/www/project
        - ./php/php-ini-overrides.ini:/etc/php/7.0/fpm/conf.d/99-overrides.ini
      links:
        - mysql      

    webserver:
      image: nginx
      container_name: project-websrv
      working_dir: /var/www/project
      volumes:
          - ../../Sources/project/trunk/src/:/var/www/project
          - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf  
      ports:
       - "8080:80"
      links:
       - php-fpm

Folder structure:

php/
 - Dockerfile
 - php-ini-overrides.ini
mysql/
nginx/
 - nginx.conf
*docker-compose.yml

full nginx.conf

server {
    listen 80 default;

    client_max_body_size 108M;

    access_log /var/log/nginx/application.access.log;

    root /var/www/project/web;
    index app_dev.php;

    rewrite ^/app\.php/?(.*)$ /$1 permanent;

    try_files $uri @rewriteapp;

    location @rewriteapp {
        rewrite ^(.*)$ /app_dev.php/$1 last;
    }

    # Deny all . files
    location ~ /\. {
        deny all;
    }

    location ~ ^/(app|app_dev)\.php(/|$) {
        fastcgi_pass php-fpm:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_index app.php;
        send_timeout 1800;
        fastcgi_read_timeout 1800;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        include fastcgi_params;
    }

    # Statics
        location /(bundles|media) {
        access_log off;
        expires 30d;
        try_files $uri @rewriteapp;
    }
}

I check URL twice and everything seems like be ok, nginx.conf is set and store in this URL. The Same configuration I use for another container, only without phpmyadmin and mariadb, and it works fine.

Upvotes: 4

Views: 7013

Answers (1)

User
User

Reputation: 14853

I found some help in the documentation on how to add aliases: https://docs.docker.com/compose/compose-file/#aliases

services:
  # ...
  php-fpm:
    # ... 
    networks:
      proxy: # maybe use "default" here
        aliases:
        - php-fpm
  webserver:
    # ...
    links: # seems to have no effect alone
    - php-fpm
    networks:
    - proxy # maybe you can also use the "default" network
    depends_on: # start this container after the dependencies
    - php-fpm

networks:
  proxy:

This answer could be simplified with your feedback. What do you really need to add?

Upvotes: 4

Related Questions